﻿using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using FDEE.Model;
using FDEECommonTools;
using FDEEInterface;
using FDEEPublicFunc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FDEEDrawingModels
{
    public class DrawingBufferTable
    {
        static string _dwgPath = "";//构造物
        static string _blcName = "MI12";
        static double tbH = 0;
        public static void DrawIBlockDepthTable(Database db, double scale, string dwgPath, System.Data.DataTable dtRes, ref string pierdiv, string title = "MAINLINE",string tkPath="")
        {          
            Point2d CT = Point2d.Origin.Convert2D(0, -2 * scale);
          
            //ext = new Extents2d(M1, M1);
            _dwgPath = dwgPath;
            IBufferReber ret = new IBufferReber("", "", 0, 0, dtRes);
            //IBufferReberNew ret = new IBufferReberNew("", "", 0, 0, dtRes);
            ret.SetRebarList();
            List<Tuple<string, RebarCollection, double,int>> bufferRebarTuples = ret.bufferRebarTuples;

            int pdfNum = 1; //水平
            int pageNo = 0; //垂直方向
            if(bufferRebarTuples.Count>0)
            {
                pierdiv = bufferRebarTuples[0].Item1+ "-"+ bufferRebarTuples[bufferRebarTuples.Count-1].Item1;
                List<Tuple<int, List<Extents2d>>> tuples = new List<Tuple<int, List<Extents2d>>>();
                pageNo = bufferRebarTuples.Count;
                for(int i=0;i<pageNo;i++)
                {
                    Extents2d ext = new Extents2d(CT.Convert2D(0,-297 * i), CT.Convert2D(0, -297 * i));
                    Extents2d ext1 = new Extents2d(CT.Convert2D(420, -297 * i), CT.Convert2D(420, -297 * i));
                    Point2d pt = CT.Convert2D(0, -297 * i);
                    Tuple<string, RebarCollection, double, int> tuple = bufferRebarTuples[i];
                    pdfNum = 1;
                    if (bufferRebarTuples[i].Item1 != "RP-15")
                    {
                        if (tuple.Item2.Count > 12)
                            pdfNum = 2;
                    }
                  

                    List<Extents2d> lst = new List<Extents2d>();
                    if (pdfNum == 1)
                    {
                        Table lasTb;
                       if( bufferRebarTuples[i].Item1 != "RP-15")
                            lasTb = DrawOnePdfColumnTable(db, ref ext, ref ext1, pt.Convert3D(), Extensions.curFont, 1, tuple, title);
                       else
                            lasTb = DrawOnePdfColumnTableNew_old(db, ref ext, ref ext1, pt.Convert3D(), Extensions.curFont, 1, tuple, title);
                        List<string> mergeList = new List<string>();
                        mergeList.Add("Materials");
                        mergeList.Add("Materials");
                        mergeList.Add("Unit");
                        mergeList.Add("Weight(kg)");
                        mergeList.Add("Total(kg)");

                        Point3d ptM = pt.Convert3D((lasTb.Width - 226) * 0.5, /*-20*/-lasTb.Height - 40 * 1);
                        Extents2d extMerge = new Extents2d(ptM.Convert2D(), ptM.Convert2D());
                        Table tb = DrawMergeColumnTable(db, tuple, ref extMerge, ptM, mergeList,
                            Extensions.curFont, 1);
                        double width = 0;
                        double height = 0;
                        if (tb != null)
                        {
                            width = tb.Width;
                            height = tb.Height;

                            string str1 = string.Format("QUANTITIES OF CONCRETE BUFFER FOR {0} OF {1} ({2} CONCRETE BUFFER)", tuple.Item1, title, tuple.Item4);

                            TextPloter.PrintScaleDoubleSideText(db, ptM.Convert2D(width / 2, 4 * 1), 3, str1, "", ref extMerge, 1, Extensions.curFont);
                        }
                        lst.Add(ext);
                        lst.Add(extMerge);
                    }
                    else
                    {
                        Table lasTb;
                         if (bufferRebarTuples[i].Item1 != "RP-16")
                        {
                            lasTb = DrawTwoPdfColumnTable(db, ref ext, ref ext1, pt.Convert3D(), Extensions.curFont, 1, tuple, title);
                        }
                         else
                        {
                            lasTb = DrawTwoPdfColumnTableNew_old(db, ref ext, ref ext1, pt.Convert3D(), Extensions.curFont, 1, tuple, title);
                        }
                        List<string> mergeList = new List<string>();
                        mergeList.Add("Materials");
                        mergeList.Add("Materials");
                        mergeList.Add("Unit");
                        mergeList.Add("Weight(kg)");
                        mergeList.Add("Total(kg)");

                        Point3d ptM = pt.Convert3D(420  + (lasTb.Width - 226) * 0.5, -lasTb.Height - 40 * 1);
                        Extents2d extMerge = new Extents2d(ptM.Convert2D(), ptM.Convert2D());
                        Table tb = DrawMergeColumnTable(db, tuple, ref extMerge, ptM, mergeList,
                            Extensions.curFont, 1);
                        double width = 0;
                        double height = 0;
                        if (tb != null)
                        {
                            width = tb.Width;
                            height = tb.Height;

                            string str1 = string.Format("QUANTITIES OF CONCRETE BUFFER FOR {0} OF {1} ({2} CONCRETE BUFFER)", tuple.Item1, title, tuple.Item4);

                            TextPloter.PrintScaleDoubleSideText(db, ptM.Convert2D(width / 2, 8 * 1), 3, str1, "", ref extMerge, 1, Extensions.curFont);
                        }
                        lst.Add(ext);
                        lst.Add(ext1);
                        lst.Add(extMerge);
                    }
                    Tuple<int, List<Extents2d>> tup = new Tuple<int, List<Extents2d>>(i, lst);
                    tuples.Add(tup);

                }

                Common.CreateIBufferLayout(db, "I梁挡块钢筋及高度", tuples, scale, tkPath);
            }
           
        }
        public static void DrawIBlockDepthTableNew(Database db, double scale, string dwgPath, System.Data.DataTable dtRes, ref string pierdiv, string title = "MAINLINE", string tkPath = "")
        {
            Point2d CT = Point2d.Origin.Convert2D(0, -2 * scale);

            //ext = new Extents2d(M1, M1);
            _dwgPath = dwgPath;

            IBufferReberNew ret = new IBufferReberNew("", "", 0, 0, dtRes);
            ret.SetRebarList();
            List<Tuple<string, RebarCollection, double, int>> bufferRebarTuples = ret.bufferRebarTuples;

            int pdfNum = 1; //水平
            int pageNo = 0; //垂直方向
            if (bufferRebarTuples.Count > 0)
            {
                pierdiv = bufferRebarTuples[0].Item1 + "-" + bufferRebarTuples[bufferRebarTuples.Count - 1].Item1;
                List<Tuple<int, List<Extents2d>>> tuples = new List<Tuple<int, List<Extents2d>>>();
                pageNo = bufferRebarTuples.Count;
                for (int i = 0; i < pageNo; i++)
                {
                    Extents2d ext = new Extents2d(CT.Convert2D(0, -297 * i), CT.Convert2D(0, -297 * i));
                    Extents2d ext1 = new Extents2d(CT.Convert2D(420, -297 * i), CT.Convert2D(420, -297 * i));
                    Point2d pt = CT.Convert2D(0, -297 * i);
                    Tuple<string, RebarCollection, double, int> tuple = bufferRebarTuples[i];
                    pdfNum = 1;
                    if (bufferRebarTuples[i].Item1 != "RP-15")
                    {
                        if (tuple.Item2.Count > 12)
                            pdfNum = 2;
                    }


                    List<Extents2d> lst = new List<Extents2d>();
                    if (pdfNum == 1)
                    {
                        Table lasTb;
                        if (bufferRebarTuples[i].Item1 != "RP-15")
                            lasTb = DrawOnePdfColumnTable(db, ref ext, ref ext1, pt.Convert3D(), Extensions.curFont, 1, tuple, title);
                        else
                            lasTb = DrawOnePdfColumnTableNew(db, ref ext, ref ext1, pt.Convert3D(), Extensions.curFont, 1, tuple, title);
                        List<string> mergeList = new List<string>();
                        mergeList.Add("Materials");
                        mergeList.Add("Materials");
                        mergeList.Add("Unit");
                        mergeList.Add("Weight(kg)");
                        mergeList.Add("Total(kg)");

                        Point3d ptM = pt.Convert3D((lasTb.Width - 226) * 0.5, /*-20*/-lasTb.Height - 40 * 1);
                        Extents2d extMerge = new Extents2d(ptM.Convert2D(), ptM.Convert2D());
                        Table tb = DrawMergeColumnTable(db, tuple, ref extMerge, ptM, mergeList,
                            Extensions.curFont, 1);
                        double width = 0;
                        double height = 0;
                        if (tb != null)
                        {
                            width = tb.Width;
                            height = tb.Height;

                            string str1 = string.Format("QUANTITIES OF CONCRETE BUFFER FOR {0} OF {1} ({2} CONCRETE BUFFER)", tuple.Item1, title, tuple.Item4);

                            TextPloter.PrintScaleDoubleSideText(db, ptM.Convert2D(width / 2, 4 * 1), 3, str1, "", ref extMerge, 1, Extensions.curFont);
                        }
                        lst.Add(ext);
                        lst.Add(extMerge);
                    }
                    else
                    {
                        Table lasTb;
                        if (bufferRebarTuples[i].Item1 != "RP-16")
                        {
                            lasTb = DrawTwoPdfColumnTable(db, ref ext, ref ext1, pt.Convert3D(), Extensions.curFont, 1, tuple, title);
                        }
                        else
                        {
                            lasTb = DrawTwoPdfColumnTableNew(db, ref ext, ref ext1, pt.Convert3D(), Extensions.curFont, 1, tuple, title);
                        }
                        List<string> mergeList = new List<string>();
                        mergeList.Add("Materials");
                        mergeList.Add("Materials");
                        mergeList.Add("Unit");
                        mergeList.Add("Weight(kg)");
                        mergeList.Add("Total(kg)");

                        Point3d ptM = pt.Convert3D(420 + (lasTb.Width - 226) * 0.5, -lasTb.Height - 40 * 1);
                        Extents2d extMerge = new Extents2d(ptM.Convert2D(), ptM.Convert2D());
                        Table tb = DrawMergeColumnTable(db, tuple, ref extMerge, ptM, mergeList,
                            Extensions.curFont, 1);
                        double width = 0;
                        double height = 0;
                        if (tb != null)
                        {
                            width = tb.Width;
                            height = tb.Height;

                            string str1 = string.Format("QUANTITIES OF CONCRETE BUFFER FOR {0} OF {1} ({2} CONCRETE BUFFER)", tuple.Item1, title, tuple.Item4);

                            TextPloter.PrintScaleDoubleSideText(db, ptM.Convert2D(width / 2, 8 * 1), 3, str1, "", ref extMerge, 1, Extensions.curFont);
                        }
                        lst.Add(ext);
                        lst.Add(ext1);
                        lst.Add(extMerge);
                    }
                    Tuple<int, List<Extents2d>> tup = new Tuple<int, List<Extents2d>>(i, lst);
                    tuples.Add(tup);

                }

                Common.CreateIBufferLayout(db, "I梁挡块钢筋及高度", tuples, scale, tkPath);
            }

        }

        public static Table DrawOnePdfColumnTable(Database db, ref Extents2d ext, ref Extents2d ext1, Point3d startPoint,
 string txtStyle, double scale, Tuple<string, RebarCollection, double, int> tuple,  string title = "MAINLINE")
        {
            int rowNum = 2 + tuple.Item2.Count;
           
            string pierName = tuple.Item1;
            int bufferCount = (int)tuple.Item4;
            //表格表头
            List<string> headName = new List<string>();
            headName.Add("Bar\\PMark");
            headName.Add("Reinf.\\PType");
            headName.Add("Sharp Configuration");
            headName.Add("Typical\\PFormula");
            headName.Add("R\\P(mm)");
            headName.Add("d\\P(mm)");
            headName.Add("r\\P(mm)");
            headName.Add("h\\P(mm)");
            headName.Add("n\\P(mm)");
            headName.Add("Lx\\P(mm)");
            headName.Add("A\\P(mm)");
            headName.Add("B\\P(mm)");
            headName.Add("C\\P(mm)");
            headName.Add("D\\P(mm)");
            headName.Add("E\\P(mm)");
            headName.Add("Quantity\\P(No./Ea.)");
            headName.Add("Length\\P(m./Ea.)");
            headName.Add("Total Length\\P(m)");
            headName.Add("Unit Weight\\P(kg/m)");
            headName.Add("Total Weight\\P(kg)");
            tbH = 0;

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForWrite) as BlockTable;
                BlockTableRecord modelSpace = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace],
                    OpenMode.ForWrite) as BlockTableRecord;

                ObjectId id;
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                id = st[txtStyle];
                //int rowNum = tbValue.Count + 2;
                // 创建table 
                startPoint = startPoint.Convert3D();
                Table tb = new Table();
                int colNum = headName.Count;
                tb.SetSize(rowNum, colNum);       // 设置几行几列
                tb.Position = startPoint;
                tb.GenerateLayout();
                #region 第一页
                #region 第一行 标题


                tb.Cells[0, 0].TextString = String.Format("TABLE OF REINFORCEMENT BAR LIST OF CONCRETE BUFFER  FOR {0} OF " + title + "({1} CONCRETE BUFFER)",
                       pierName, bufferCount);

                tb.Cells[0, 0].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[0, 0].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[0, 0].Contents[0].Rotation = 0;
                //tb.Cells[0, 0].Borders.Horizontal.Margin = 1 * scale;
                tb.Cells[0, 0].Contents[0].TextStyleId = id;
                #endregion
                tb.Rows[0].Height = 9 * scale;

                #region 第二行 表格标题
                for (int i = 0; i < colNum; ++i)
                {
                    tb.Cells[1, i].TextString = headName[i]; //获取i行j列数据
                    tb.Cells[1, i].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[1, i].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[1, i].Contents[0].Rotation = 0;
                    tb.Cells[1, i].Borders.Horizontal.Margin = 1 * scale;
                    tb.Cells[1, i].Contents[0].TextStyleId = id;
                }
                #endregion

                tb.Rows[1].Height = 16 * scale;

                #region 设置表格值
                RebarCollection tbValue = tuple.Item2;
                if (tbValue.Count > 0)
                {
                    for (int m = 0; m < tbValue.Count; m++)
                    {
                        try
                        {
                            //
                            string value = "";
                            int n = 0;
                            value = tbValue[m].MBarMark.ToString();
                            if (tbValue[m].SBarMark != 0)
                                value = tbValue[m].MBarMark.ToString() + "." + tbValue[m].SBarMark.ToString() + tbValue[m].CBarMark;
                            else
                                value = tbValue[m].MBarMark.ToString() + "\\P(" + tbValue[m].CBarMark + ")";
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                            tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                            tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                            tb.Cells[m + 2, n].Contents[0].TextStyleId = id;

                            n++;
                            tb.Cells[m + 2, n].TextString = tbValue[m].Diameter.ToString(); //获取i行j列数据
                            tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                            tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                            tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                            tb.Cells[m + 2, n].Contents[0].TextStyleId = id;

                            //Formula
                            n = n + 2;
                            tb.Cells[m + 2, n].TextString = tbValue[m].Formula == null ? "-" : tbValue[m].Formula; //获取i行j列数据
                            tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                            tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                            tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                            tb.Cells[m + 2, n].Contents[0].TextStyleId = id;

                            //R
                            n++;
                            value = "";
                            if (tbValue[m].R != 0)
                                value = tbValue[m].R.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //d
                            n++;
                            value = "";
                            if (tbValue[m].Diameter != 0)
                            {
                                value = System.Text.RegularExpressions.Regex.Replace(tbValue[m].Diameter.ToString(), @"[^0-9]+", "");
                            }
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //r
                            n++;
                            value = "";
                            if (tbValue[m].r != 0)
                                value = tbValue[m].r.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //h
                            n++;
                            value = "";
                            if (tbValue[m].h != 0)
                                value = tbValue[m].h.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //n
                            n++;
                            value = "";
                            if (tbValue[m].n != 0)
                                value = tbValue[m].n.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //Lx
                            n++;
                            value = "";
                            if (tbValue[m].Lx != 0)
                                value = tbValue[m].Lx.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //A
                            n++;
                            value = "";
                            if (tbValue[m].A != 0)
                                value = tbValue[m].A.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //B
                            n++;
                            value = "";
                            if (tbValue[m].B != 0)
                                value = tbValue[m].B.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //C
                            n++;
                            value = "";
                            if (tbValue[m].C != 0)
                                value = tbValue[m].C.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //D
                            n++;
                            value = "";
                            if (tbValue[m].D != 0)
                                value = tbValue[m].D.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }
                            //E
                            n++;
                            value = "";
                            if (tbValue[m].E != 0)
                                value = tbValue[m].E.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }
                            //Quantity
                            n++;
                            value = "";
                            if (tbValue[m].Quantity != 0)
                                value = tbValue[m].Quantity.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //Length
                            n++;
                            value = "";
                            if (tbValue[m].Length != 0)
                                value = tbValue[m].Length.ToString("0.000").Trim();

                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].TextString = value;// string.Format("{0:N3}", double.Parse(value)); //获取i行j列数据
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //TotalLength
                            n++;
                            value = "";
                            if (tbValue[m].TotalLength != 0)
                                value = tbValue[m].TotalLength.ToString("0.000").Trim();

                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].TextString = value;// string.Format("{0:N3}", double.Parse(value));
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //UnitWeight
                            n++;
                            value = "";
                            if (tbValue[m].UnitWeight != 0)
                                value = tbValue[m].UnitWeight.ToString("0.000").Trim();

                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].TextString = value;// string.Format("{0:N3}", double.Parse(value));
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //TotalWeight
                            n++;
                            value = "";
                            if (tbValue[m].TotalWeight != 0)
                                value = tbValue[m].TotalWeight.ToString("0.000").Trim();

                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].TextString = value;// string.Format("{0:N3}", double.Parse(value));
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            if (tbValue[m].ShapeConfg.ToString().Contains("MO"))
                                _blcName = "MO";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MUC"))
                                _blcName = "MUC";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MUR"))
                                _blcName = "MUR";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MU"))
                                _blcName = "MU";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MSZR"))
                                _blcName = "MSZR";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MSZ"))
                                _blcName = "MSZ";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MIXCR"))
                                _blcName = "MIXCR0";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MIXC"))
                                _blcName = "MIXC0";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MIXAR"))
                                _blcName = "MIXAR0";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MIXA"))
                                _blcName = "MIXA0";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MA"))
                                _blcName = "MA";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MCT"))
                                _blcName = "MCT";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MCB"))
                                _blcName = "MCB";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MCR"))
                                _blcName = "MCR";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MCL"))
                                _blcName = "MCL";
                            db.CopyBlockFromFile(_dwgPath, _blcName);

                            BlockTool.InsertBlockReference(startPoint.Convert3D(4 * 3 * scale + 5 * 3 * scale + 8 * 3 * scale, -(9 * scale + 16 * scale + 16 * m + 8)), 0.8, _blcName, _dwgPath, 0);

                        }
                        catch (Exception ex)
                        { }

                    }
                }

                #endregion

                #region 表格添加数据

                #endregion

                #region 设置列宽
                // 设置列宽
                for (int i = 0; i < colNum; ++i)
                {
                    if (i == 0)
                        tb.Columns[i].Width = 5 * 3 * scale;
                    else if (i == 1)
                        tb.Columns[i].Width = 5 * 3 * scale;
                    else if (i == 2)
                        tb.Columns[i].Width = 16 * 3 * scale;
                    else if (i == 3)
                        tb.Columns[i].Width = 11 * 3 * scale;
                    else if (i > headName.Count - 4)
                        tb.Columns[i].Width = 9 * 3 * scale;
                    else if (i > headName.Count - 6)
                        tb.Columns[i].Width = 8 * 3 * scale;
                    else
                        tb.Columns[i].Width = 4 * 3 * scale;
                }
                #endregion

                //行高
                for (int i = 2; i < rowNum; ++i)
                {
                    tb.Rows[i].Height = 16 * scale;
                }

                #region 列单元格合并



                #endregion

                tb.Layer = "细线";
                tb.LineWeight = LineWeight.LineWeight013;
                tb.ColorIndex = 4;
                modelSpace.AppendEntity(tb);
                tr.AddNewlyCreatedDBObject(tb, true);
                ext = ext.Add(new Extents2d(tb.Bounds.Value.MinPoint.Convert2D(), tb.Bounds.Value.MaxPoint.Convert2D()));

                #region  边框粗线设置
                List<Point2d> pList = new List<Point2d>();
                Point2d pt1 = startPoint.Convert2D();
                pList.Add(pt1);
                Point2d pt2 = pt1.Convert2D(0, -tb.Height);
                pList.Add(pt2);
                Point2d pt3 = pt1.Convert2D(tb.Width, -tb.Height);
                pList.Add(pt3);
                Point2d pt4 = pt1.Convert2D(tb.Width, 0);
                pList.Add(pt4);
                PolylinePloter.AddPolylineByList(db, ref ext, pList, "粗线", 2);
                #endregion

                #endregion

                #region 其他页

                #endregion
                tr.Commit();
                return tb;
            }
            
        }
        public static Table DrawOnePdfColumnTableNew(Database db, ref Extents2d ext, ref Extents2d ext1, Point3d startPoint,
string txtStyle, double scale, Tuple<string, RebarCollection, double, int> tuple, string title = "MAINLINE")
        {
            int rowNum = 2 + tuple.Item2.Count;

            string pierName = tuple.Item1;
            int bufferCount = (int)tuple.Item4;
            //表格表头
            List<string> headName = new List<string>();
            headName.Add("Bar\\PMark");
            headName.Add("Reinf.\\PType");
            headName.Add("Sharp Configuration");
            headName.Add("Typical\\PFormula");
            headName.Add("R\\P(mm)");
            headName.Add("d\\P(mm)");
            headName.Add("r\\P(mm)");
            headName.Add("h\\P(mm)");
            headName.Add("n\\P(mm)");
            headName.Add("Lx\\P(mm)");
            headName.Add("A\\P(mm)");
            headName.Add("B\\P(mm)");
            headName.Add("C\\P(mm)");
            headName.Add("D\\P(mm)");
            headName.Add("E\\P(mm)");
            headName.Add("Quantity\\P(No./Ea.)");
            headName.Add("Length\\P(m./Ea.)");
            headName.Add("Total Length\\P(m)");
            headName.Add("Unit Weight\\P(kg/m)");
            headName.Add("Total Weight\\P(kg)");
            tbH = 0;

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForWrite) as BlockTable;
                BlockTableRecord modelSpace = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace],
                    OpenMode.ForWrite) as BlockTableRecord;

                ObjectId id;
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                id = st[txtStyle];
                //int rowNum = tbValue.Count + 2;
                // 创建table 
                startPoint = startPoint.Convert3D();
                Table tb = new Table();
                int colNum = headName.Count;
                tb.SetSize(rowNum, colNum);       // 设置几行几列
                tb.Position = startPoint;
                tb.GenerateLayout();
                #region 第一页
                #region 第一行 标题


                tb.Cells[0, 0].TextString = String.Format("TABLE OF REINFORCEMENT BAR LIST OF CONCRETE BUFFER  FOR {0} OF " + title + "({1} CONCRETE BUFFER)",
                       pierName, bufferCount);

                tb.Cells[0, 0].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[0, 0].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[0, 0].Contents[0].Rotation = 0;
                //tb.Cells[0, 0].Borders.Horizontal.Margin = 1 * scale;
                tb.Cells[0, 0].Contents[0].TextStyleId = id;
                #endregion
                tb.Rows[0].Height = 9 * scale;

                #region 第二行 表格标题
                for (int i = 0; i < colNum; ++i)
                {
                    tb.Cells[1, i].TextString = headName[i]; //获取i行j列数据
                    tb.Cells[1, i].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[1, i].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[1, i].Contents[0].Rotation = 0;
                    tb.Cells[1, i].Borders.Horizontal.Margin = 1 * scale;
                    tb.Cells[1, i].Contents[0].TextStyleId = id;
                }
                #endregion

                tb.Rows[1].Height = 16 * scale;

                #region 设置表格值
                RebarCollection tbValue = tuple.Item2;
                if (tbValue.Count > 0)
                {
                    for (int m = 0; m < tbValue.Count; m++)
                    {
                        try
                        {
                            //
                            string value = "";
                            int n = 0;
                            value = tbValue[m].MBarMark.ToString();
                            if (tbValue[m].SBarMark != 0)
                                value = tbValue[m].MBarMark.ToString() + "." + tbValue[m].SBarMark.ToString() + tbValue[m].CBarMark;
                            else
                                value = tbValue[m].MBarMark.ToString() + "\\P(" + tbValue[m].CBarMark + ")";
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                            tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                            tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                            tb.Cells[m + 2, n].Contents[0].TextStyleId = id;

                            n++;
                            tb.Cells[m + 2, n].TextString = tbValue[m].Diameter.ToString(); //获取i行j列数据
                            tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                            tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                            tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                            tb.Cells[m + 2, n].Contents[0].TextStyleId = id;

                            //Formula
                            n = n + 2;
                            tb.Cells[m + 2, n].TextString = tbValue[m].Formula == null ? "-" : tbValue[m].Formula; //获取i行j列数据
                            tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                            tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                            tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                            tb.Cells[m + 2, n].Contents[0].TextStyleId = id;

                            //R
                            n++;
                            value = "";
                            if (tbValue[m].R != 0)
                                value = tbValue[m].R.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //d
                            n++;
                            value = "";
                            if (tbValue[m].Diameter != 0)
                            {
                                value = System.Text.RegularExpressions.Regex.Replace(tbValue[m].Diameter.ToString(), @"[^0-9]+", "");
                            }
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //r
                            n++;
                            value = "";
                            if (tbValue[m].r != 0)
                                value = tbValue[m].r.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //h
                            n++;
                            value = "";
                            if (tbValue[m].h != 0)
                                value = tbValue[m].h.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //n
                            n++;
                            value = "";
                            if (tbValue[m].n != 0)
                                value = tbValue[m].n.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //Lx
                            n++;
                            value = "";
                            if (tbValue[m].Lx != 0)
                                value = tbValue[m].Lx.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //A
                            n++;
                            value = "";
                            if (tbValue[m].A != 0)
                                value = tbValue[m].A.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //B
                            n++;
                            value = "";
                            if (tbValue[m].B != 0)
                                value = tbValue[m].B.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //C
                            n++;
                            value = "";
                            if (tbValue[m].C != 0)
                                value = tbValue[m].C.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //D
                            n++;
                            value = "";
                            if (tbValue[m].D != 0)
                                value = tbValue[m].D.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }
                            //E
                            n++;
                            value = "";
                            if (tbValue[m].E != 0)
                                value = tbValue[m].E.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }
                            //Quantity
                            n++;
                            value = "";
                            if (tbValue[m].Quantity != 0)
                                value = tbValue[m].Quantity.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //Length
                            n++;
                            value = "";
                            if (tbValue[m].Length != 0)
                                value = tbValue[m].Length.ToString("0.000").Trim();

                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].TextString = value;// string.Format("{0:N3}", double.Parse(value)); //获取i行j列数据
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //TotalLength
                            n++;
                            value = "";
                            if (tbValue[m].TotalLength != 0)
                                value = tbValue[m].TotalLength.ToString("0.000").Trim();

                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].TextString = value;// string.Format("{0:N3}", double.Parse(value));
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //UnitWeight
                            n++;
                            value = "";
                            if (tbValue[m].UnitWeight != 0)
                                value = tbValue[m].UnitWeight.ToString("0.000").Trim();

                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].TextString = value;// string.Format("{0:N3}", double.Parse(value));
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //TotalWeight
                            n++;
                            value = "";
                            if (tbValue[m].TotalWeight != 0)
                                value = tbValue[m].TotalWeight.ToString("0.000").Trim();

                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].TextString = value;// string.Format("{0:N3}", double.Parse(value));
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                                if (m % 4 == 0)
                                    tb.MergeCells(CellRange.Create(tb, m + 3, 2, m + 5, 2));
                            }

                            if (tbValue[m].ShapeConfg.ToString().Contains("MO"))
                                _blcName = "MO";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MUC"))
                                _blcName = "MUC";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MUR"))
                                _blcName = "MUR";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MU"))
                                _blcName = "MU";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MSZR"))
                                _blcName = "MSZR";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MSZ"))
                                _blcName = "MSZ";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MIXCR"))
                                _blcName = "MIXCR0";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MIXC"))
                                _blcName = "MIXC0";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MIXAR"))
                                _blcName = "MIXAR0";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MIXA"))
                                _blcName = "MIXA0";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MA"))
                                _blcName = "MA";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MCT"))
                                _blcName = "MCT";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MCB"))
                                _blcName = "MCB";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MCR"))
                                _blcName = "MCR";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MCL"))
                                _blcName = "MCL";
                            db.CopyBlockFromFile(_dwgPath, _blcName);
                            int co = 0;
                            if (m / 4.0 > (int)m / 4)
                                co = (int)m / 4 + 1;
                            else
                                co = (int)m / 4;
                            if (m % 4 == 0)
                            {
                                if (m == 0)
                                    BlockTool.InsertBlockReference(startPoint.Convert3D(4 * 3 * scale + 5 * 3 * scale + 8 * 3 * scale, -(9 * scale + 16 * scale + 15 * m + 8)), 0.8, _blcName, _dwgPath, 0);
                                else
                                    BlockTool.InsertBlockReference(startPoint.Convert3D(4 * 3 * scale + 5 * 3 * scale + 8 * 3 * scale, -(9 * scale + 16 * scale + 15 * co + 27 * co + 8)), 0.8, _blcName, _dwgPath, 0);
                            }
                            else if (m % 4 == 2)
                                BlockTool.InsertBlockReference(startPoint.Convert3D(4 * 3 * scale + 5 * 3 * scale + 8 * 3 * scale, -(9 * scale + 16 * scale + 15 * co  + 9 * (m - co) + 4)), 0.8, _blcName, _dwgPath, 0);

                        }
                        catch (Exception ex)
                        { }

                    }
                }

                #endregion

                #region 表格添加数据

                #endregion

                #region 设置列宽
                // 设置列宽
                for (int i = 0; i < colNum; ++i)
                {
                    if (i == 0)
                        tb.Columns[i].Width = 5 * 3 * scale;
                    else if (i == 1)
                        tb.Columns[i].Width = 5 * 3 * scale;
                    else if (i == 2)
                        tb.Columns[i].Width = 16 * 3 * scale;
                    else if (i == 3)
                        tb.Columns[i].Width = 11 * 3 * scale;
                    else if (i > headName.Count - 4)
                        tb.Columns[i].Width = 9 * 3 * scale;
                    else if (i > headName.Count - 6)
                        tb.Columns[i].Width = 8 * 3 * scale;
                    else
                        tb.Columns[i].Width = 4 * 3 * scale;
                }
                #endregion

                //行高
                for (int i = 2; i < rowNum; ++i)
                {
                    if ((i + 2) % 4 != 0 )
                        tb.Rows[i].Height = 9 * scale;
                    else
                        tb.Rows[i].Height = 15 * scale;
                }

                #region 列单元格合并



                #endregion

                tb.Layer = "细线";
                tb.LineWeight = LineWeight.LineWeight013;
                tb.ColorIndex = 4;
                modelSpace.AppendEntity(tb);
                tr.AddNewlyCreatedDBObject(tb, true);
                ext = ext.Add(new Extents2d(tb.Bounds.Value.MinPoint.Convert2D(), tb.Bounds.Value.MaxPoint.Convert2D()));

                #region  边框粗线设置
                List<Point2d> pList = new List<Point2d>();
                Point2d pt1 = startPoint.Convert2D();
                pList.Add(pt1);
                Point2d pt2 = pt1.Convert2D(0, -tb.Height);
                pList.Add(pt2);
                Point2d pt3 = pt1.Convert2D(tb.Width, -tb.Height);
                pList.Add(pt3);
                Point2d pt4 = pt1.Convert2D(tb.Width, 0);
                pList.Add(pt4);
                PolylinePloter.AddPolylineByList(db, ref ext, pList, "粗线", 2);
                #endregion

                #endregion

                #region 其他页

                #endregion
                tr.Commit();
                return tb;
            }

        }
 
        public static Table DrawTwoPdfColumnTable(Database db, ref Extents2d ext, ref Extents2d ext1, Point3d startPoint,
  string txtStyle, double scale, Tuple<string, RebarCollection, double, int> tuple, string title = "MAINLINE")
        {
            int rowNum = 2 + tuple.Item2.Count;

            string pierName = tuple.Item1;
            int bufferCount = (int)tuple.Item4;
            //表格表头
            List<string> headName = new List<string>();
            headName.Add("Bar\\PMark");
            headName.Add("Reinf.\\PType");
            headName.Add("Sharp Configuration");
            headName.Add("Typical\\PFormula");
            headName.Add("R\\P(mm)");
            headName.Add("d\\P(mm)");
            headName.Add("r\\P(mm)");
            headName.Add("h\\P(mm)");
            headName.Add("n\\P(mm)");
            headName.Add("Lx\\P(mm)");
            headName.Add("A\\P(mm)");
            headName.Add("B\\P(mm)");
            headName.Add("C\\P(mm)");
            headName.Add("D\\P(mm)");
            headName.Add("E\\P(mm)");
            headName.Add("Quantity\\P(No./Ea.)");
            headName.Add("Length\\P(m./Ea.)");
            headName.Add("Total Length\\P(m)");
            headName.Add("Unit Weight\\P(kg/m)");
            headName.Add("Total Weight\\P(kg)");
            tbH = 0;

         
                //int rowNum = tbValue.Count + 2;
            Table tb = new Table();
            // 创建table 
            for (int num = 0; num < 2; num++)
            {
                using (Transaction tr = db.TransactionManager.StartTransaction())
                {
                    BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForWrite) as BlockTable;
                    BlockTableRecord modelSpace = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace],
                        OpenMode.ForWrite) as BlockTableRecord;

                    ObjectId id;
                    TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                    id = st[txtStyle];
                    startPoint = startPoint.Convert3D(420 * num);
                    if (num == 0)
                        rowNum = 2 + 12;
                    else
                        rowNum = 2 + tuple.Item2.Count - 12;
                    tb = new Table();
                    int colNum = headName.Count;
                    tb.SetSize(rowNum, colNum);       // 设置几行几列
                    tb.Position = startPoint;
                    tb.GenerateLayout();
                    #region 第一页
                    #region 第一行 标题


                    tb.Cells[0, 0].TextString = String.Format("TABLE OF REINFORCEMENT BAR LIST OF CONCRETE BUFFER  FOR {0} OF " + title + "({1} CONCRETE BUFFER)",
                           pierName, bufferCount);

                    tb.Cells[0, 0].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[0, 0].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[0, 0].Contents[0].Rotation = 0;
                    //tb.Cells[0, 0].Borders.Horizontal.Margin = 1 * scale;
                    tb.Cells[0, 0].Contents[0].TextStyleId = id;
                    #endregion
                    tb.Rows[0].Height = 9 * scale;

                    #region 第二行 表格标题
                    for (int i = 0; i < colNum; ++i)
                    {
                        tb.Cells[1, i].TextString = headName[i]; //获取i行j列数据
                        tb.Cells[1, i].Contents[0].TextHeight = 2.5 * scale;
                        tb.Cells[1, i].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[1, i].Contents[0].Rotation = 0;
                        tb.Cells[1, i].Borders.Horizontal.Margin = 1 * scale;
                        tb.Cells[1, i].Contents[0].TextStyleId = id;
                    }
                    #endregion

                    tb.Rows[1].Height = 16 * scale;

                    #region 设置表格值
                    RebarCollection tbValue = tuple.Item2;
                    if (tbValue.Count > 0)
                    {
                        int startNo = 0, endNo = 12;
                        if (num == 0)
                        {
                            startNo = 0;
                            endNo = 12;
                        }
                        else
                        {
                            startNo = 12;
                            endNo = tbValue.Count;
                        }
                        for (int m = startNo; m < endNo; m++)
                        {
                            try
                            {
                                //
                                string value = "";
                                int n = 0;
                                value = tbValue[m].MBarMark.ToString();
                                if (tbValue[m].SBarMark != 0)
                                    value = tbValue[m].MBarMark.ToString() + "." + tbValue[m].SBarMark.ToString() + tbValue[m].CBarMark;
                                else
                                    value = tbValue[m].MBarMark.ToString() + "\\P(" + tbValue[m].CBarMark + ")";
                                tb.Cells[m + 2 - startNo, n].TextString = value; //获取i行j列数据
                                tb.Cells[m + 2 - startNo, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2 - startNo, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2 - startNo, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2 - startNo, n].Contents[0].TextStyleId = id;

                                n++;
                                tb.Cells[m + 2 - startNo, n].TextString = tbValue[m].Diameter.ToString(); //获取i行j列数据
                                tb.Cells[m + 2 - startNo, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2 - startNo, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2 - startNo, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2 - startNo, n].Contents[0].TextStyleId = id;

                                //Formula
                                n = n + 2;
                                tb.Cells[m + 2 - startNo, n].TextString = tbValue[m].Formula == null ? "-" : tbValue[m].Formula; //获取i行j列数据
                                tb.Cells[m + 2 - startNo, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2 - startNo, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2 - startNo, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2 - startNo, n].Contents[0].TextStyleId = id;

                                //R
                                n++;
                                value = "";
                                if (tbValue[m].R != 0)
                                    value = tbValue[m].R.ToString();
                                tb.Cells[m + 2 - startNo, n].TextString = value; //获取i行j列数据
                                if (!string.IsNullOrWhiteSpace(value))
                                {
                                    tb.Cells[m + 2 - startNo, n].Contents[0].TextHeight = 2 * scale;
                                    tb.Cells[m + 2 - startNo, n].Alignment = CellAlignment.MiddleCenter;
                                    tb.Cells[m + 2 - startNo, n].Borders.Horizontal.Margin = 1 * scale;
                                    tb.Cells[m + 2 - startNo, n].Contents[0].TextStyleId = id;
                                }

                                //d
                                n++;
                                value = "";
                                if (tbValue[m].Diameter != 0)
                                {
                                    value = System.Text.RegularExpressions.Regex.Replace(tbValue[m].Diameter.ToString(), @"[^0-9]+", "");
                                }
                                tb.Cells[m + 2 - startNo, n].TextString = value; //获取i行j列数据
                                if (!string.IsNullOrWhiteSpace(value))
                                {
                                    tb.Cells[m + 2 - startNo, n].Contents[0].TextHeight = 2 * scale;
                                    tb.Cells[m + 2 - startNo, n].Alignment = CellAlignment.MiddleCenter;
                                    tb.Cells[m + 2 - startNo, n].Borders.Horizontal.Margin = 1 * scale;
                                    tb.Cells[m + 2 - startNo, n].Contents[0].TextStyleId = id;
                                }

                                //r
                                n++;
                                value = "";
                                if (tbValue[m].r != 0)
                                    value = tbValue[m].r.ToString();
                                tb.Cells[m + 2 - startNo, n].TextString = value; //获取i行j列数据
                                if (!string.IsNullOrWhiteSpace(value))
                                {
                                    tb.Cells[m + 2 - startNo, n].Contents[0].TextHeight = 2 * scale;
                                    tb.Cells[m + 2 - startNo, n].Alignment = CellAlignment.MiddleCenter;
                                    tb.Cells[m + 2 - startNo, n].Borders.Horizontal.Margin = 1 * scale;
                                    tb.Cells[m + 2 - startNo, n].Contents[0].TextStyleId = id;
                                }

                                //h
                                n++;
                                value = "";
                                if (tbValue[m].h != 0)
                                    value = tbValue[m].h.ToString();
                                tb.Cells[m + 2 - startNo, n].TextString = value; //获取i行j列数据
                                if (!string.IsNullOrWhiteSpace(value))
                                {
                                    tb.Cells[m + 2 - startNo, n].Contents[0].TextHeight = 2 * scale;
                                    tb.Cells[m + 2 - startNo, n].Alignment = CellAlignment.MiddleCenter;
                                    tb.Cells[m + 2 - startNo, n].Borders.Horizontal.Margin = 1 * scale;
                                    tb.Cells[m + 2 - startNo, n].Contents[0].TextStyleId = id;
                                }

                                //n
                                n++;
                                value = "";
                                if (tbValue[m].n != 0)
                                    value = tbValue[m].n.ToString();
                                tb.Cells[m + 2 - startNo, n].TextString = value; //获取i行j列数据
                                if (!string.IsNullOrWhiteSpace(value))
                                {
                                    tb.Cells[m + 2 - startNo, n].Contents[0].TextHeight = 2 * scale;
                                    tb.Cells[m + 2 - startNo, n].Alignment = CellAlignment.MiddleCenter;
                                    tb.Cells[m + 2 - startNo, n].Borders.Horizontal.Margin = 1 * scale;
                                    tb.Cells[m + 2 - startNo, n].Contents[0].TextStyleId = id;
                                }

                                //Lx
                                n++;
                                value = "";
                                if (tbValue[m].Lx != 0)
                                    value = tbValue[m].Lx.ToString();
                                tb.Cells[m + 2 - startNo, n].TextString = value; //获取i行j列数据
                                if (!string.IsNullOrWhiteSpace(value))
                                {
                                    tb.Cells[m + 2 - startNo, n].Contents[0].TextHeight = 2 * scale;
                                    tb.Cells[m + 2 - startNo, n].Alignment = CellAlignment.MiddleCenter;
                                    tb.Cells[m + 2 - startNo, n].Borders.Horizontal.Margin = 1 * scale;
                                    tb.Cells[m + 2 - startNo, n].Contents[0].TextStyleId = id;
                                }

                                //A
                                n++;
                                value = "";
                                if (tbValue[m].A != 0)
                                    value = tbValue[m].A.ToString();
                                tb.Cells[m + 2 - startNo, n].TextString = value; //获取i行j列数据
                                if (!string.IsNullOrWhiteSpace(value))
                                {
                                    tb.Cells[m + 2 - startNo, n].Contents[0].TextHeight = 2 * scale;
                                    tb.Cells[m + 2 - startNo, n].Alignment = CellAlignment.MiddleCenter;
                                    tb.Cells[m + 2 - startNo, n].Borders.Horizontal.Margin = 1 * scale;
                                    tb.Cells[m + 2 - startNo, n].Contents[0].TextStyleId = id;
                                }

                                //B
                                n++;
                                value = "";
                                if (tbValue[m].B != 0)
                                    value = tbValue[m].B.ToString();
                                tb.Cells[m + 2 - startNo, n].TextString = value; //获取i行j列数据
                                if (!string.IsNullOrWhiteSpace(value))
                                {
                                    tb.Cells[m + 2 - startNo, n].Contents[0].TextHeight = 2 * scale;
                                    tb.Cells[m + 2 - startNo, n].Alignment = CellAlignment.MiddleCenter;
                                    tb.Cells[m + 2 - startNo, n].Borders.Horizontal.Margin = 1 * scale;
                                    tb.Cells[m + 2 - startNo, n].Contents[0].TextStyleId = id;
                                }

                                //C
                                n++;
                                value = "";
                                if (tbValue[m].C != 0)
                                    value = tbValue[m].C.ToString();
                                tb.Cells[m + 2 - startNo, n].TextString = value; //获取i行j列数据
                                if (!string.IsNullOrWhiteSpace(value))
                                {
                                    tb.Cells[m + 2 - startNo, n].Contents[0].TextHeight = 2 * scale;
                                    tb.Cells[m + 2 - startNo, n].Alignment = CellAlignment.MiddleCenter;
                                    tb.Cells[m + 2 - startNo, n].Borders.Horizontal.Margin = 1 * scale;
                                    tb.Cells[m + 2 - startNo, n].Contents[0].TextStyleId = id;
                                }

                                //D
                                n++;
                                value = "";
                                if (tbValue[m].D != 0)
                                    value = tbValue[m].D.ToString();
                                tb.Cells[m + 2 - startNo, n].TextString = value; //获取i行j列数据
                                if (!string.IsNullOrWhiteSpace(value))
                                {
                                    tb.Cells[m + 2 - startNo, n].Contents[0].TextHeight = 2 * scale;
                                    tb.Cells[m + 2 - startNo, n].Alignment = CellAlignment.MiddleCenter;
                                    tb.Cells[m + 2 - startNo, n].Borders.Horizontal.Margin = 1 * scale;
                                    tb.Cells[m + 2 - startNo, n].Contents[0].TextStyleId = id;
                                }
                                //E
                                n++;
                                value = "";
                                if (tbValue[m].E != 0)
                                    value = tbValue[m].E.ToString();
                                tb.Cells[m + 2 - startNo, n].TextString = value; //获取i行j列数据
                                if (!string.IsNullOrWhiteSpace(value))
                                {
                                    tb.Cells[m + 2 - startNo, n].Contents[0].TextHeight = 2 * scale;
                                    tb.Cells[m + 2 - startNo, n].Alignment = CellAlignment.MiddleCenter;
                                    tb.Cells[m + 2 - startNo, n].Borders.Horizontal.Margin = 1 * scale;
                                    tb.Cells[m + 2 - startNo, n].Contents[0].TextStyleId = id;
                                }
                                //Quantity
                                n++;
                                value = "";
                                if (tbValue[m].Quantity != 0)
                                    value = tbValue[m].Quantity.ToString();
                                tb.Cells[m + 2 - startNo, n].TextString = value; //获取i行j列数据
                                if (!string.IsNullOrWhiteSpace(value))
                                {
                                    tb.Cells[m + 2 - startNo, n].Contents[0].TextHeight = 2 * scale;
                                    tb.Cells[m + 2 - startNo, n].Alignment = CellAlignment.MiddleCenter;
                                    tb.Cells[m + 2 - startNo, n].Borders.Horizontal.Margin = 1 * scale;
                                    tb.Cells[m + 2 - startNo, n].Contents[0].TextStyleId = id;
                                }

                                //Length
                                n++;
                                value = "";
                                if (tbValue[m].Length != 0)
                                    value = tbValue[m].Length.ToString("0.000").Trim();

                                if (!string.IsNullOrWhiteSpace(value))
                                {
                                    tb.Cells[m + 2 - startNo, n].TextString = value;// string.Format("{0:N3}", double.Parse(value)); //获取i行j列数据
                                    tb.Cells[m + 2 - startNo, n].Contents[0].TextHeight = 2 * scale;
                                    tb.Cells[m + 2 - startNo, n].Alignment = CellAlignment.MiddleCenter;
                                    tb.Cells[m + 2 - startNo, n].Borders.Horizontal.Margin = 1 * scale;
                                    tb.Cells[m + 2 - startNo, n].Contents[0].TextStyleId = id;
                                }

                                //TotalLength
                                n++;
                                value = "";
                                if (tbValue[m].TotalLength != 0)
                                    value = tbValue[m].TotalLength.ToString("0.000").Trim();

                                if (!string.IsNullOrWhiteSpace(value))
                                {
                                    tb.Cells[m + 2 - startNo, n].TextString = value;// string.Format("{0:N3}", double.Parse(value));
                                    tb.Cells[m + 2 - startNo, n].Contents[0].TextHeight = 2 * scale;
                                    tb.Cells[m + 2 - startNo, n].Alignment = CellAlignment.MiddleCenter;
                                    tb.Cells[m + 2 - startNo, n].Borders.Horizontal.Margin = 1 * scale;
                                    tb.Cells[m + 2 - startNo, n].Contents[0].TextStyleId = id;
                                }

                                //UnitWeight
                                n++;
                                value = "";
                                if (tbValue[m].UnitWeight != 0)
                                    value = tbValue[m].UnitWeight.ToString("0.000").Trim();

                                if (!string.IsNullOrWhiteSpace(value))
                                {
                                    tb.Cells[m + 2 - startNo, n].TextString = value;// string.Format("{0:N3}", double.Parse(value));
                                    tb.Cells[m + 2 - startNo, n].Contents[0].TextHeight = 2 * scale;
                                    tb.Cells[m + 2 - startNo, n].Alignment = CellAlignment.MiddleCenter;
                                    tb.Cells[m + 2 - startNo, n].Borders.Horizontal.Margin = 1 * scale;
                                    tb.Cells[m + 2 - startNo, n].Contents[0].TextStyleId = id;
                                }

                                //TotalWeight
                                n++;
                                value = "";
                                if (tbValue[m].TotalWeight != 0)
                                    value = tbValue[m].TotalWeight.ToString("0.000").Trim();

                                if (!string.IsNullOrWhiteSpace(value))
                                {
                                    tb.Cells[m + 2 - startNo, n].TextString = value;// string.Format("{0:N3}", double.Parse(value));
                                    tb.Cells[m + 2 - startNo, n].Contents[0].TextHeight = 2 * scale;
                                    tb.Cells[m + 2 - startNo, n].Alignment = CellAlignment.MiddleCenter;
                                    tb.Cells[m + 2 - startNo, n].Borders.Horizontal.Margin = 1 * scale;
                                    tb.Cells[m + 2 - startNo, n].Contents[0].TextStyleId = id;
                                }

                                if (tbValue[m].ShapeConfg.ToString().Contains("MO"))
                                    _blcName = "MO";
                                else if (tbValue[m].ShapeConfg.ToString().Contains("MUC"))
                                    _blcName = "MUC";
                                else if (tbValue[m].ShapeConfg.ToString().Contains("MUR"))
                                    _blcName = "MUR";
                                else if (tbValue[m].ShapeConfg.ToString().Contains("MU"))
                                    _blcName = "MU";
                                else if (tbValue[m].ShapeConfg.ToString().Contains("MSZR"))
                                    _blcName = "MSZR";
                                else if (tbValue[m].ShapeConfg.ToString().Contains("MSZ"))
                                    _blcName = "MSZ";
                                else if (tbValue[m].ShapeConfg.ToString().Contains("MIXCR"))
                                    _blcName = "MIXCR0";
                                else if (tbValue[m].ShapeConfg.ToString().Contains("MIXC"))
                                    _blcName = "MIXC0";
                                else if (tbValue[m].ShapeConfg.ToString().Contains("MIXAR"))
                                    _blcName = "MIXAR0";
                                else if (tbValue[m].ShapeConfg.ToString().Contains("MIXA"))
                                    _blcName = "MIXA0";
                                else if (tbValue[m].ShapeConfg.ToString().Contains("MA"))
                                    _blcName = "MA";
                                else if (tbValue[m].ShapeConfg.ToString().Contains("MCT"))
                                    _blcName = "MCT";
                                else if (tbValue[m].ShapeConfg.ToString().Contains("MCB"))
                                    _blcName = "MCB";
                                else if (tbValue[m].ShapeConfg.ToString().Contains("MCR"))
                                    _blcName = "MCR";
                                else if (tbValue[m].ShapeConfg.ToString().Contains("MCL"))
                                    _blcName = "MCL";
                                db.CopyBlockFromFile(_dwgPath, _blcName);

                                BlockTool.InsertBlockReference(startPoint.Convert3D(4 * 3 * scale + 5 * 3 * scale + 8 * 3 * scale, -(9 * scale + 16 * scale + 16 * (m - startNo) + 8)), 0.8, _blcName, _dwgPath, 0);

                            }
                            catch (Exception ex)
                            { }

                        }
                    }

                    #endregion

                    #region 表格添加数据

                    #endregion

                    #region 设置列宽
                    // 设置列宽
                    for (int i = 0; i < colNum; ++i)
                    {
                        if (i == 0)
                            tb.Columns[i].Width = 5 * 3 * scale;
                        else if (i == 1)
                            tb.Columns[i].Width = 5 * 3 * scale;
                        else if (i == 2)
                            tb.Columns[i].Width = 16 * 3 * scale;
                        else if (i == 3)
                            tb.Columns[i].Width = 11 * 3 * scale;
                        else if (i > headName.Count - 4)
                            tb.Columns[i].Width = 9 * 3 * scale;
                        else if (i > headName.Count - 6)
                            tb.Columns[i].Width = 8 * 3 * scale;
                        else
                            tb.Columns[i].Width = 4 * 3 * scale;
                    }
                    #endregion

                    //行高
                    for (int i = 2; i < rowNum; ++i)
                    {
                        tb.Rows[i].Height = 16 * scale;
                    }

                    #region 列单元格合并



                    #endregion

                    tb.Layer = "细线";
                    tb.LineWeight = LineWeight.LineWeight013;
                    tb.ColorIndex = 4;
                    modelSpace.AppendEntity(tb);
                    tr.AddNewlyCreatedDBObject(tb, true);
                    if (num == 0)
                        ext = ext.Add(new Extents2d(tb.Bounds.Value.MinPoint.Convert2D(), tb.Bounds.Value.MaxPoint.Convert2D()));
                    else
                        ext1 = ext1.Add(new Extents2d(tb.Bounds.Value.MinPoint.Convert2D(), tb.Bounds.Value.MaxPoint.Convert2D()));

                    #region  边框粗线设置
                    List<Point2d> pList = new List<Point2d>();
                    Point2d pt1 = startPoint.Convert2D();
                    pList.Add(pt1);
                    Point2d pt2 = pt1.Convert2D(0, -tb.Height);
                    pList.Add(pt2);
                    Point2d pt3 = pt1.Convert2D(tb.Width, -tb.Height);
                    pList.Add(pt3);
                    Point2d pt4 = pt1.Convert2D(tb.Width, 0);
                    pList.Add(pt4);
                    if (num == 0)
                        PolylinePloter.AddPolylineByList(db, ref ext, pList, "粗线", 2);
                    else
                        PolylinePloter.AddPolylineByList(db, ref ext1, pList, "粗线", 2);
                    #endregion

                    #endregion

                    #region 其他页

                    #endregion
                    tr.Commit();
                }

            }
            return tb;
        }

        public static Table DrawTwoPdfColumnTableNew(Database db, ref Extents2d ext, ref Extents2d ext1, Point3d startPoint,
string txtStyle, double scale, Tuple<string, RebarCollection, double, int> tuple, string title = "MAINLINE")
        {
            int rowNum = 2 + tuple.Item2.Count;

            string pierName = tuple.Item1;
            int bufferCount = (int)tuple.Item4;
            //表格表头
            List<string> headName = new List<string>();
            headName.Add("Bar\\PMark");
            headName.Add("Reinf.\\PType");
            headName.Add("Sharp Configuration");
            headName.Add("Typical\\PFormula");
            headName.Add("R\\P(mm)");
            headName.Add("d\\P(mm)");
            headName.Add("r\\P(mm)");
            headName.Add("h\\P(mm)");
            headName.Add("n\\P(mm)");
            headName.Add("Lx\\P(mm)");
            headName.Add("A\\P(mm)");
            headName.Add("B\\P(mm)");
            headName.Add("C\\P(mm)");
            headName.Add("D\\P(mm)");
            headName.Add("E\\P(mm)");
            headName.Add("Quantity\\P(No./Ea.)");
            headName.Add("Length\\P(m./Ea.)");
            headName.Add("Total Length\\P(m)");
            headName.Add("Unit Weight\\P(kg/m)");
            headName.Add("Total Weight\\P(kg)");
            tbH = 0;


            //int rowNum = tbValue.Count + 2;
            Table tb = new Table();
            // 创建table 
            for (int num = 0; num < 2; num++)
            {
                using (Transaction tr = db.TransactionManager.StartTransaction())
                {
                    BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForWrite) as BlockTable;
                    BlockTableRecord modelSpace = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace],
                        OpenMode.ForWrite) as BlockTableRecord;

                    ObjectId id;
                    TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                    id = st[txtStyle];
                    startPoint = startPoint.Convert3D(420 * num);
                    if (num == 0)
                        rowNum = 2 + 12;
                    else
                        rowNum = 2 + tuple.Item2.Count - 12;
                    tb = new Table();
                    int colNum = headName.Count;
                    tb.SetSize(rowNum, colNum);       // 设置几行几列
                    tb.Position = startPoint;
                    tb.GenerateLayout();
                    #region 第一页
                    #region 第一行 标题


                    tb.Cells[0, 0].TextString = String.Format("TABLE OF REINFORCEMENT BAR LIST OF CONCRETE BUFFER  FOR {0} OF " + title + "({1} CONCRETE BUFFER)",
                           pierName, bufferCount);

                    tb.Cells[0, 0].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[0, 0].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[0, 0].Contents[0].Rotation = 0;
                    //tb.Cells[0, 0].Borders.Horizontal.Margin = 1 * scale;
                    tb.Cells[0, 0].Contents[0].TextStyleId = id;
                    #endregion
                    tb.Rows[0].Height = 9 * scale;

                    #region 第二行 表格标题
                    for (int i = 0; i < colNum; ++i)
                    {
                        tb.Cells[1, i].TextString = headName[i]; //获取i行j列数据
                        tb.Cells[1, i].Contents[0].TextHeight = 2.5 * scale;
                        tb.Cells[1, i].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[1, i].Contents[0].Rotation = 0;
                        tb.Cells[1, i].Borders.Horizontal.Margin = 1 * scale;
                        tb.Cells[1, i].Contents[0].TextStyleId = id;
                    }
                    #endregion

                    tb.Rows[1].Height = 16 * scale;

                    #region 设置表格值
                    RebarCollection tbValue = tuple.Item2;
                    if (tbValue.Count > 0)
                    {
                        int startNo = 0, endNo = 12;
                        if (num == 0)
                        {
                            startNo = 0;
                            endNo = 12;
                        }
                        else
                        {
                            startNo = 12;
                            endNo = tbValue.Count;
                        }
                        for (int m = startNo; m < endNo; m++)
                        {
                            try
                            {
                                //
                                string value = "";
                                int n = 0;
                                value = tbValue[m].MBarMark.ToString();
                                if (tbValue[m].SBarMark != 0)
                                    value = tbValue[m].MBarMark.ToString() + "." + tbValue[m].SBarMark.ToString() + tbValue[m].CBarMark;
                                else
                                    value = tbValue[m].MBarMark.ToString() + "\\P(" + tbValue[m].CBarMark + ")";
                                tb.Cells[m + 2 - startNo, n].TextString = value; //获取i行j列数据
                                tb.Cells[m + 2 - startNo, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2 - startNo, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2 - startNo, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2 - startNo, n].Contents[0].TextStyleId = id;

                                n++;
                                tb.Cells[m + 2 - startNo, n].TextString = tbValue[m].Diameter.ToString(); //获取i行j列数据
                                tb.Cells[m + 2 - startNo, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2 - startNo, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2 - startNo, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2 - startNo, n].Contents[0].TextStyleId = id;

                                //Formula
                                n = n + 2;
                                tb.Cells[m + 2 - startNo, n].TextString = tbValue[m].Formula == null ? "-" : tbValue[m].Formula; //获取i行j列数据
                                tb.Cells[m + 2 - startNo, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2 - startNo, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2 - startNo, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2 - startNo, n].Contents[0].TextStyleId = id;

                                //R
                                n++;
                                value = "";
                                if (tbValue[m].R != 0)
                                    value = tbValue[m].R.ToString();
                                tb.Cells[m + 2 - startNo, n].TextString = value; //获取i行j列数据
                                if (!string.IsNullOrWhiteSpace(value))
                                {
                                    tb.Cells[m + 2 - startNo, n].Contents[0].TextHeight = 2 * scale;
                                    tb.Cells[m + 2 - startNo, n].Alignment = CellAlignment.MiddleCenter;
                                    tb.Cells[m + 2 - startNo, n].Borders.Horizontal.Margin = 1 * scale;
                                    tb.Cells[m + 2 - startNo, n].Contents[0].TextStyleId = id;
                                }

                                //d
                                n++;
                                value = "";
                                if (tbValue[m].Diameter != 0)
                                {
                                    value = System.Text.RegularExpressions.Regex.Replace(tbValue[m].Diameter.ToString(), @"[^0-9]+", "");
                                }
                                tb.Cells[m + 2 - startNo, n].TextString = value; //获取i行j列数据
                                if (!string.IsNullOrWhiteSpace(value))
                                {
                                    tb.Cells[m + 2 - startNo, n].Contents[0].TextHeight = 2 * scale;
                                    tb.Cells[m + 2 - startNo, n].Alignment = CellAlignment.MiddleCenter;
                                    tb.Cells[m + 2 - startNo, n].Borders.Horizontal.Margin = 1 * scale;
                                    tb.Cells[m + 2 - startNo, n].Contents[0].TextStyleId = id;
                                }

                                //r
                                n++;
                                value = "";
                                if (tbValue[m].r != 0)
                                    value = tbValue[m].r.ToString();
                                tb.Cells[m + 2 - startNo, n].TextString = value; //获取i行j列数据
                                if (!string.IsNullOrWhiteSpace(value))
                                {
                                    tb.Cells[m + 2 - startNo, n].Contents[0].TextHeight = 2 * scale;
                                    tb.Cells[m + 2 - startNo, n].Alignment = CellAlignment.MiddleCenter;
                                    tb.Cells[m + 2 - startNo, n].Borders.Horizontal.Margin = 1 * scale;
                                    tb.Cells[m + 2 - startNo, n].Contents[0].TextStyleId = id;
                                }

                                //h
                                n++;
                                value = "";
                                if (tbValue[m].h != 0)
                                    value = tbValue[m].h.ToString();
                                tb.Cells[m + 2 - startNo, n].TextString = value; //获取i行j列数据
                                if (!string.IsNullOrWhiteSpace(value))
                                {
                                    tb.Cells[m + 2 - startNo, n].Contents[0].TextHeight = 2 * scale;
                                    tb.Cells[m + 2 - startNo, n].Alignment = CellAlignment.MiddleCenter;
                                    tb.Cells[m + 2 - startNo, n].Borders.Horizontal.Margin = 1 * scale;
                                    tb.Cells[m + 2 - startNo, n].Contents[0].TextStyleId = id;
                                }

                                //n
                                n++;
                                value = "";
                                if (tbValue[m].n != 0)
                                    value = tbValue[m].n.ToString();
                                tb.Cells[m + 2 - startNo, n].TextString = value; //获取i行j列数据
                                if (!string.IsNullOrWhiteSpace(value))
                                {
                                    tb.Cells[m + 2 - startNo, n].Contents[0].TextHeight = 2 * scale;
                                    tb.Cells[m + 2 - startNo, n].Alignment = CellAlignment.MiddleCenter;
                                    tb.Cells[m + 2 - startNo, n].Borders.Horizontal.Margin = 1 * scale;
                                    tb.Cells[m + 2 - startNo, n].Contents[0].TextStyleId = id;
                                }

                                //Lx
                                n++;
                                value = "";
                                if (tbValue[m].Lx != 0)
                                    value = tbValue[m].Lx.ToString();
                                tb.Cells[m + 2 - startNo, n].TextString = value; //获取i行j列数据
                                if (!string.IsNullOrWhiteSpace(value))
                                {
                                    tb.Cells[m + 2 - startNo, n].Contents[0].TextHeight = 2 * scale;
                                    tb.Cells[m + 2 - startNo, n].Alignment = CellAlignment.MiddleCenter;
                                    tb.Cells[m + 2 - startNo, n].Borders.Horizontal.Margin = 1 * scale;
                                    tb.Cells[m + 2 - startNo, n].Contents[0].TextStyleId = id;
                                }

                                //A
                                n++;
                                value = "";
                                if (tbValue[m].A != 0)
                                    value = tbValue[m].A.ToString();
                                tb.Cells[m + 2 - startNo, n].TextString = value; //获取i行j列数据
                                if (!string.IsNullOrWhiteSpace(value))
                                {
                                    tb.Cells[m + 2 - startNo, n].Contents[0].TextHeight = 2 * scale;
                                    tb.Cells[m + 2 - startNo, n].Alignment = CellAlignment.MiddleCenter;
                                    tb.Cells[m + 2 - startNo, n].Borders.Horizontal.Margin = 1 * scale;
                                    tb.Cells[m + 2 - startNo, n].Contents[0].TextStyleId = id;
                                }

                                //B
                                n++;
                                value = "";
                                if (tbValue[m].B != 0)
                                    value = tbValue[m].B.ToString();
                                tb.Cells[m + 2 - startNo, n].TextString = value; //获取i行j列数据
                                if (!string.IsNullOrWhiteSpace(value))
                                {
                                    tb.Cells[m + 2 - startNo, n].Contents[0].TextHeight = 2 * scale;
                                    tb.Cells[m + 2 - startNo, n].Alignment = CellAlignment.MiddleCenter;
                                    tb.Cells[m + 2 - startNo, n].Borders.Horizontal.Margin = 1 * scale;
                                    tb.Cells[m + 2 - startNo, n].Contents[0].TextStyleId = id;
                                  
                                }

                                //C
                                n++;
                                value = "";
                                if (tbValue[m].C != 0)
                                    value = tbValue[m].C.ToString();
                                tb.Cells[m + 2 - startNo, n].TextString = value; //获取i行j列数据
                                if (!string.IsNullOrWhiteSpace(value))
                                {
                                    tb.Cells[m + 2 - startNo, n].Contents[0].TextHeight = 2 * scale;
                                    tb.Cells[m + 2 - startNo, n].Alignment = CellAlignment.MiddleCenter;
                                    tb.Cells[m + 2 - startNo, n].Borders.Horizontal.Margin = 1 * scale;
                                    tb.Cells[m + 2 - startNo, n].Contents[0].TextStyleId = id;
                                }

                                //D
                                n++;
                                value = "";
                                if (tbValue[m].D != 0)
                                    value = tbValue[m].D.ToString();
                                tb.Cells[m + 2 - startNo, n].TextString = value; //获取i行j列数据
                                if (!string.IsNullOrWhiteSpace(value))
                                {
                                    tb.Cells[m + 2 - startNo, n].Contents[0].TextHeight = 2 * scale;
                                    tb.Cells[m + 2 - startNo, n].Alignment = CellAlignment.MiddleCenter;
                                    tb.Cells[m + 2 - startNo, n].Borders.Horizontal.Margin = 1 * scale;
                                    tb.Cells[m + 2 - startNo, n].Contents[0].TextStyleId = id;
                                }
                                //E
                                n++;
                                value = "";
                                if (tbValue[m].E != 0)
                                    value = tbValue[m].E.ToString();
                                tb.Cells[m + 2 - startNo, n].TextString = value; //获取i行j列数据
                                if (!string.IsNullOrWhiteSpace(value))
                                {
                                    tb.Cells[m + 2 - startNo, n].Contents[0].TextHeight = 2 * scale;
                                    tb.Cells[m + 2 - startNo, n].Alignment = CellAlignment.MiddleCenter;
                                    tb.Cells[m + 2 - startNo, n].Borders.Horizontal.Margin = 1 * scale;
                                    tb.Cells[m + 2 - startNo, n].Contents[0].TextStyleId = id;
                                }
                                //Quantity
                                n++;
                                value = "";
                                if (tbValue[m].Quantity != 0)
                                    value = tbValue[m].Quantity.ToString();
                                tb.Cells[m + 2 - startNo, n].TextString = value; //获取i行j列数据
                                if (!string.IsNullOrWhiteSpace(value))
                                {
                                    tb.Cells[m + 2 - startNo, n].Contents[0].TextHeight = 2 * scale;
                                    tb.Cells[m + 2 - startNo, n].Alignment = CellAlignment.MiddleCenter;
                                    tb.Cells[m + 2 - startNo, n].Borders.Horizontal.Margin = 1 * scale;
                                    tb.Cells[m + 2 - startNo, n].Contents[0].TextStyleId = id;
                                }

                                //Length
                                n++;
                                value = "";
                                if (tbValue[m].Length != 0)
                                    value = tbValue[m].Length.ToString("0.000").Trim();

                                if (!string.IsNullOrWhiteSpace(value))
                                {
                                    tb.Cells[m + 2 - startNo, n].TextString = value;// string.Format("{0:N3}", double.Parse(value)); //获取i行j列数据
                                    tb.Cells[m + 2 - startNo, n].Contents[0].TextHeight = 2 * scale;
                                    tb.Cells[m + 2 - startNo, n].Alignment = CellAlignment.MiddleCenter;
                                    tb.Cells[m + 2 - startNo, n].Borders.Horizontal.Margin = 1 * scale;
                                    tb.Cells[m + 2 - startNo, n].Contents[0].TextStyleId = id;
                                }

                                //TotalLength
                                n++;
                                value = "";
                                if (tbValue[m].TotalLength != 0)
                                    value = tbValue[m].TotalLength.ToString("0.000").Trim();

                                if (!string.IsNullOrWhiteSpace(value))
                                {
                                    tb.Cells[m + 2 - startNo, n].TextString = value;// string.Format("{0:N3}", double.Parse(value));
                                    tb.Cells[m + 2 - startNo, n].Contents[0].TextHeight = 2 * scale;
                                    tb.Cells[m + 2 - startNo, n].Alignment = CellAlignment.MiddleCenter;
                                    tb.Cells[m + 2 - startNo, n].Borders.Horizontal.Margin = 1 * scale;
                                    tb.Cells[m + 2 - startNo, n].Contents[0].TextStyleId = id;
                                }

                                //UnitWeight
                                n++;
                                value = "";
                                if (tbValue[m].UnitWeight != 0)
                                    value = tbValue[m].UnitWeight.ToString("0.000").Trim();

                                if (!string.IsNullOrWhiteSpace(value))
                                {
                                    tb.Cells[m + 2 - startNo, n].TextString = value;// string.Format("{0:N3}", double.Parse(value));
                                    tb.Cells[m + 2 - startNo, n].Contents[0].TextHeight = 2 * scale;
                                    tb.Cells[m + 2 - startNo, n].Alignment = CellAlignment.MiddleCenter;
                                    tb.Cells[m + 2 - startNo, n].Borders.Horizontal.Margin = 1 * scale;
                                    tb.Cells[m + 2 - startNo, n].Contents[0].TextStyleId = id;
                                }

                                //TotalWeight
                                n++;
                                value = "";
                                if (tbValue[m].TotalWeight != 0)
                                    value = tbValue[m].TotalWeight.ToString("0.000").Trim();

                                if (!string.IsNullOrWhiteSpace(value))
                                {
                                    tb.Cells[m + 2 - startNo, n].TextString = value;// string.Format("{0:N3}", double.Parse(value));
                                    tb.Cells[m + 2 - startNo, n].Contents[0].TextHeight = 2 * scale;
                                    tb.Cells[m + 2 - startNo, n].Alignment = CellAlignment.MiddleCenter;
                                    tb.Cells[m + 2 - startNo, n].Borders.Horizontal.Margin = 1 * scale;
                                    tb.Cells[m + 2 - startNo, n].Contents[0].TextStyleId = id;
                                    if (m % 4 == 0&&num==1)
                                        tb.MergeCells(CellRange.Create(tb, m + 3 - startNo, 2, m + 5 - startNo, 2));
                                }

                                if (tbValue[m].ShapeConfg.ToString().Contains("MO"))
                                    _blcName = "MO";
                                else if (tbValue[m].ShapeConfg.ToString().Contains("MUC"))
                                    _blcName = "MUC";
                                else if (tbValue[m].ShapeConfg.ToString().Contains("MUR"))
                                    _blcName = "MUR";
                                else if (tbValue[m].ShapeConfg.ToString().Contains("MU"))
                                    _blcName = "MU";
                                else if (tbValue[m].ShapeConfg.ToString().Contains("MSZR"))
                                    _blcName = "MSZR";
                                else if (tbValue[m].ShapeConfg.ToString().Contains("MSZ"))
                                    _blcName = "MSZ";
                                else if (tbValue[m].ShapeConfg.ToString().Contains("MIXCR"))
                                    _blcName = "MIXCR0";
                                else if (tbValue[m].ShapeConfg.ToString().Contains("MIXC"))
                                    _blcName = "MIXC0";
                                else if (tbValue[m].ShapeConfg.ToString().Contains("MIXAR"))
                                    _blcName = "MIXAR0";
                                else if (tbValue[m].ShapeConfg.ToString().Contains("MIXA"))
                                    _blcName = "MIXA0";
                                else if (tbValue[m].ShapeConfg.ToString().Contains("MA"))
                                    _blcName = "MA";
                                else if (tbValue[m].ShapeConfg.ToString().Contains("MCT"))
                                    _blcName = "MCT";
                                else if (tbValue[m].ShapeConfg.ToString().Contains("MCB"))
                                    _blcName = "MCB";
                                else if (tbValue[m].ShapeConfg.ToString().Contains("MCR"))
                                    _blcName = "MCR";
                                else if (tbValue[m].ShapeConfg.ToString().Contains("MCL"))
                                    _blcName = "MCL";
                                db.CopyBlockFromFile(_dwgPath, _blcName);
                                if (num == 0)
                                    BlockTool.InsertBlockReference(startPoint.Convert3D(4 * 3 * scale + 5 * 3 * scale + 8 * 3 * scale, -(9 * scale + 16 * scale + 16 * (m - startNo) + 8)), 0.8, _blcName, _dwgPath, 0);
                                else
                                {
                                    int co = 0;
                                    if (m / 4.0 > (int)m / 4)
                                        co = (int)(m - startNo) / 4 + 1;
                                    else
                                        co = (int)(m - startNo) / 4;
                                    if (m % 4 == 0)
                                    {
                                        if (m == 0)
                                            BlockTool.InsertBlockReference(startPoint.Convert3D(4 * 3 * scale + 5 * 3 * scale + 8 * 3 * scale, -(9 * scale + 16 * scale + 15 * (m - startNo) + 8)), 0.8, _blcName, _dwgPath, 0);
                                        else
                                            BlockTool.InsertBlockReference(startPoint.Convert3D(4 * 3 * scale + 5 * 3 * scale + 8 * 3 * scale, -(9 * scale + 16 * scale + 15 * co + 27 * co + 8)), 0.8, _blcName, _dwgPath, 0);
                                    }
                                    else if (m % 4 == 2)
                                        BlockTool.InsertBlockReference(startPoint.Convert3D(4 * 3 * scale + 5 * 3 * scale + 8 * 3 * scale, -(9 * scale + 16 * scale + 15 * co  + 9 * (m - startNo - co) + 4)), 0.8, _blcName, _dwgPath, 0);
                                }

                            }
                            catch (Exception ex)
                            { }

                        }
                    }

                    #endregion

                    #region 表格添加数据

                    #endregion

                    #region 设置列宽
                    // 设置列宽
                    for (int i = 0; i < colNum; ++i)
                    {
                        if (i == 0)
                            tb.Columns[i].Width = 5 * 3 * scale;
                        else if (i == 1)
                            tb.Columns[i].Width = 5 * 3 * scale;
                        else if (i == 2)
                            tb.Columns[i].Width = 16 * 3 * scale;
                        else if (i == 3)
                            tb.Columns[i].Width = 11 * 3 * scale;
                        else if (i > headName.Count - 4)
                            tb.Columns[i].Width = 9 * 3 * scale;
                        else if (i > headName.Count - 6)
                            tb.Columns[i].Width = 8 * 3 * scale;
                        else
                            tb.Columns[i].Width = 4 * 3 * scale;
                    }
                    #endregion

                    //行高
                    for (int i = 2; i < rowNum; ++i)
                    {
                        if (num == 0)
                            tb.Rows[i].Height = 16 * scale;
                        else
                        {
                            if ((i + 2) % 4 != 0)
                                tb.Rows[i].Height = 9 * scale;
                            else
                                tb.Rows[i].Height = 15 * scale;
                        }
                    }

                    #region 列单元格合并



                    #endregion

                    tb.Layer = "细线";
                    tb.LineWeight = LineWeight.LineWeight013;
                    tb.ColorIndex = 4;
                    modelSpace.AppendEntity(tb);
                    tr.AddNewlyCreatedDBObject(tb, true);
                    if (num == 0)
                        ext = ext.Add(new Extents2d(tb.Bounds.Value.MinPoint.Convert2D(), tb.Bounds.Value.MaxPoint.Convert2D()));
                    else
                        ext1 = ext1.Add(new Extents2d(tb.Bounds.Value.MinPoint.Convert2D(), tb.Bounds.Value.MaxPoint.Convert2D()));

                    #region  边框粗线设置
                    List<Point2d> pList = new List<Point2d>();
                    Point2d pt1 = startPoint.Convert2D();
                    pList.Add(pt1);
                    Point2d pt2 = pt1.Convert2D(0, -tb.Height);
                    pList.Add(pt2);
                    Point2d pt3 = pt1.Convert2D(tb.Width, -tb.Height);
                    pList.Add(pt3);
                    Point2d pt4 = pt1.Convert2D(tb.Width, 0);
                    pList.Add(pt4);
                    if (num == 0)
                        PolylinePloter.AddPolylineByList(db, ref ext, pList, "粗线", 2);
                    else
                        PolylinePloter.AddPolylineByList(db, ref ext1, pList, "粗线", 2);
                    #endregion

                    #endregion

                    #region 其他页

                    #endregion
                    tr.Commit();
                }

            }
            return tb;
        }

        public static Table DrawMergeColumnTable(Database db, Tuple<string, RebarCollection, double, int> tuple, ref Extents2d ext,
Point3d startPoint, List<string> headName, string txtStyle, double scale)
        {

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForWrite) as BlockTable;
                BlockTableRecord modelSpace = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace],
                    OpenMode.ForWrite) as BlockTableRecord;

                ObjectId id;
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                id = st[txtStyle];

                Table tb = new Table();

                Dictionary<eDB, List<RebarBase>> dic = new Dictionary<eDB, List<RebarBase>>();      // 统计合并项

                #region 统计合并数据

                RebarCollection tu = tuple.Item2;
                foreach (RebarBase item in tu)
                {
                    if (dic.Count == 0)
                    {
                        List<RebarBase> items = new List<RebarBase>();
                        items.Add(item);
                        dic[item.Diameter] = items;
                    }
                    else
                    {
                        List<RebarBase> items = new List<RebarBase>();
                        dic.TryGetValue(item.Diameter, out items);
                        if (items == null || items.Count == 0)
                        {
                            items = new List<RebarBase>();
                        }
                        items.Add(item);
                        dic[item.Diameter] = items;
                    }
                }

                #endregion

                #region 设置表格长宽

                int row = dic.Count + 2;
                int col = 5;
                row = dic.Count + 2;


                tb.SetSize(row, col);
                tb.Position = startPoint;
                tb.GenerateLayout();
                #endregion

                #region 设置表头
                for (int i = 0; i < col; ++i)
                {
                    tb.Cells[0, i].TextString = headName[i];
                    tb.Cells[0, i].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[0, i].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[0, i].Contents[0].Rotation = 0;
                    tb.Cells[0, i].Contents[0].TextStyleId = id;
                }
                #endregion

                #region 设置表格值
                // 第一行第一列
                tb.Cells[1, 0].TextString = "Bars";
                tb.Cells[1, 0].Contents[0].TextHeight = 2 * scale;
                tb.Cells[1, 0].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[1, 0].Contents[0].Rotation = 0;
                tb.Cells[1, 0].Contents[0].TextStyleId = id;

                // 第一列最后一行
                tb.Cells[dic.Count + 1, 0].TextString = "Concrete";
                tb.Cells[dic.Count + 1, 0].Contents[0].TextHeight = 2 * scale;
                tb.Cells[dic.Count + 1, 0].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[dic.Count + 1, 0].Contents[0].Rotation = 0;
                tb.Cells[dic.Count + 1, 0].Contents[0].TextStyleId = id;

                // 其他数据
                #region Bars, Concreate数据
                double totalWeight = 0;
                for (int i = 1; i < row; ++i)
                {
                    if (i == dic.Count + 1)
                    {
                        tb.Cells[i, 1].TextString = string.Format("f'c={0}MPa", 45);
                        tb.Cells[i, 1].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[i, 1].Contents[0].TextHeight = 2 * scale;
                        tb.Cells[i, 1].Contents[0].Rotation = 0;
                        tb.Cells[i, 1].Contents[0].TextStyleId = id;

                        tb.Cells[i, 2].TextString = "m3";
                        tb.Cells[i, 2].Contents[0].TextHeight = 2 * scale;
                        tb.Cells[i, 2].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[i, 2].Contents[0].Rotation = 0;
                        tb.Cells[i, 2].Contents[0].TextStyleId = id;

                        tb.Cells[i, 3].TextString = tuple.Item3.ToString("0.000")/*string.Format("{0:N3}", ret.ConcreteVolumn)*/;
                        tb.Cells[i, 3].Contents[0].TextHeight = 2 * scale;
                        tb.Cells[i, 3].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[i, 3].Contents[0].Rotation = 0;
                        tb.Cells[i, 3].Contents[0].TextStyleId = id;
                    }
                    else
                    {
                        KeyValuePair<eDB, List<RebarBase>> pr = new KeyValuePair<eDB, List<RebarBase>>();
                        if (dic.Count > i - 1)
                        {
                            pr = dic.ElementAt(i - 1);
                        }
                        if (pr.Value == null)
                        {
                            continue;
                        }

                        // 类型
                        tb.Cells[i, 1].TextString = pr.Key.ToString();
                        tb.Cells[i, 1].Contents[0].TextHeight = 2 * scale;
                        tb.Cells[i, 1].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[i, 1].Contents[0].Rotation = 0;
                        tb.Cells[i, 1].Contents[0].TextStyleId = id;

                        // 单位
                        tb.Cells[i, 2].TextString = "kg";
                        tb.Cells[i, 2].Contents[0].TextHeight = 2 * scale;
                        tb.Cells[i, 2].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[i, 2].Contents[0].Rotation = 0;
                        tb.Cells[i, 2].Contents[0].TextStyleId = id;

                        // 数量
                        double weight = 0;
                        foreach (RebarBase info in pr.Value)
                        {
                            weight += info.TotalWeight;
                        }

                        tb.Cells[i, 3].TextString = weight.ToString("0.000")/* string.Format("{0:N3}", weight)*/;
                        tb.Cells[i, 3].Contents[0].TextHeight = 2 * scale;
                        tb.Cells[i, 3].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[i, 3].Contents[0].Rotation = 0;
                        tb.Cells[i, 3].Contents[0].TextStyleId = id;

                        // 总数
                        totalWeight += weight;
                    }

                    // 总数
                    tb.Cells[1, 4].TextString = totalWeight.ToString("0.000")/*string.Format("{0:N3}", totalWeight)*/;
                    tb.Cells[1, 4].Contents[0].TextHeight = 2 * scale;
                    tb.Cells[1, 4].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[1, 4].Contents[0].Rotation = 0;
                    tb.Cells[1, 4].Contents[0].TextStyleId = id;
                }
                #endregion


                #endregion

                #region 设置行高、列宽
                for (int i = 0; i < col; ++i)
                {
                    if (i == 0)
                    {
                        tb.Columns[i].Width = 35 * scale;
                    }
                    else if (i == 1)
                    {
                        tb.Columns[i].Width = 60 * scale;
                    }
                    else if (i == 2)
                    {
                        tb.Columns[i].Width = 35 * scale;
                    }
                    else if (i == 3)
                    {
                        tb.Columns[i].Width = 48 * scale;
                    }
                    else if (i == 4)
                    {
                        tb.Columns[i].Width = 48 * scale;
                    }
                }

                for (int i = 0; i < row; ++i)
                {
                    tb.Rows[i].Height = 8 * scale;
                }
                #endregion

                #region 合并单元格
                List<CellRange> cellList = new List<CellRange>();

                CellRange range1 = CellRange.Create(tb, 1, 0, dic.Count, 0);
                cellList.Add(range1);

                CellRange range2 = CellRange.Create(tb, 1, 2, dic.Count, 2);
                cellList.Add(range2);

                CellRange range3 = CellRange.Create(tb, 1, 4, dic.Count, 4);
                cellList.Add(range3);

                CellRange range4 = CellRange.Create(tb, dic.Count + 1, 3, dic.Count + 1, 4);
                cellList.Add(range4);

                CellRange range5 = CellRange.Create(tb, 0, 0, 0, 1);
                cellList.Add(range5);



                //CellRange range6 = CellRange.Create(tb, dic.Count + 2, 3, dic.Count + 2, 4);
                //cellList.Add(range6);


                foreach (CellRange range in cellList)
                {
                    tb.MergeCells(range);
                }
                #endregion

                tb.Layer = "细线";
                tb.LineWeight = LineWeight.LineWeight013;
                tb.ColorIndex = 4;
                modelSpace.AppendEntity(tb);
                tr.AddNewlyCreatedDBObject(tb, true);
                ext = ext.Add(new Extents2d(tb.Bounds.Value.MinPoint.Convert2D(), tb.Bounds.Value.MaxPoint.Convert2D()));

                #region  边框粗线设置
                List<Point2d> pList = new List<Point2d>();
                Point2d pt1 = startPoint.Convert2D();
                pList.Add(pt1);
                Point2d pt2 = pt1.Convert2D(0, -tb.Height);
                pList.Add(pt2);
                Point2d pt3 = pt1.Convert2D(tb.Width, -tb.Height);
                pList.Add(pt3);
                Point2d pt4 = pt1.Convert2D(tb.Width, 0);
                pList.Add(pt4);
                PolylinePloter.AddPolylineByList(db, ref ext, pList, "粗线", 2);
                #endregion

                tr.Commit();
                Extents3d ex3d = new Extents3d(tb.Bounds.Value.MinPoint.Convert3D(), tb.Bounds.Value.MaxPoint.Convert3D());
                ext = ex3d.Convert2D();
                return tb;
            }
        }

        public static Table DrawOnePdfColumnTableNew_old(Database db, ref Extents2d ext, ref Extents2d ext1, Point3d startPoint,
string txtStyle, double scale, Tuple<string, RebarCollection, double, int> tuple, string title = "MAINLINE")
        {
            int rowNum = 2 + tuple.Item2.Count;

            string pierName = tuple.Item1;
            int bufferCount = (int)tuple.Item4;
            //表格表头
            List<string> headName = new List<string>();
            headName.Add("Bar\\PMark");
            headName.Add("Reinf.\\PType");
            headName.Add("Sharp Configuration");
            headName.Add("Typical\\PFormula");
            headName.Add("R\\P(mm)");
            headName.Add("d\\P(mm)");
            headName.Add("r\\P(mm)");
            headName.Add("h\\P(mm)");
            headName.Add("n\\P(mm)");
            headName.Add("Lx\\P(mm)");
            headName.Add("A\\P(mm)");
            headName.Add("B\\P(mm)");
            headName.Add("C\\P(mm)");
            headName.Add("D\\P(mm)");
            headName.Add("E\\P(mm)");
            headName.Add("Quantity\\P(No./Ea.)");
            headName.Add("Length\\P(m./Ea.)");
            headName.Add("Total Length\\P(m)");
            headName.Add("Unit Weight\\P(kg/m)");
            headName.Add("Total Weight\\P(kg)");
            tbH = 0;

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForWrite) as BlockTable;
                BlockTableRecord modelSpace = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace],
                    OpenMode.ForWrite) as BlockTableRecord;

                ObjectId id;
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                id = st[txtStyle];
                //int rowNum = tbValue.Count + 2;
                // 创建table 
                startPoint = startPoint.Convert3D();
                Table tb = new Table();
                int colNum = headName.Count;
                tb.SetSize(rowNum, colNum);       // 设置几行几列
                tb.Position = startPoint;
                tb.GenerateLayout();
                #region 第一页
                #region 第一行 标题


                tb.Cells[0, 0].TextString = String.Format("TABLE OF REINFORCEMENT BAR LIST OF CONCRETE BUFFER  FOR {0} OF " + title + "({1} CONCRETE BUFFER)",
                       pierName, bufferCount);

                tb.Cells[0, 0].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[0, 0].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[0, 0].Contents[0].Rotation = 0;
                //tb.Cells[0, 0].Borders.Horizontal.Margin = 1 * scale;
                tb.Cells[0, 0].Contents[0].TextStyleId = id;
                #endregion
                tb.Rows[0].Height = 9 * scale;

                #region 第二行 表格标题
                for (int i = 0; i < colNum; ++i)
                {
                    tb.Cells[1, i].TextString = headName[i]; //获取i行j列数据
                    tb.Cells[1, i].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[1, i].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[1, i].Contents[0].Rotation = 0;
                    tb.Cells[1, i].Borders.Horizontal.Margin = 1 * scale;
                    tb.Cells[1, i].Contents[0].TextStyleId = id;
                }
                #endregion

                tb.Rows[1].Height = 16 * scale;

                #region 设置表格值
                RebarCollection tbValue = tuple.Item2;
                if (tbValue.Count > 0)
                {
                    for (int m = 0; m < tbValue.Count; m++)
                    {
                        try
                        {
                            //
                            string value = "";
                            int n = 0;
                            value = tbValue[m].MBarMark.ToString();
                            if (tbValue[m].SBarMark != 0)
                                value = tbValue[m].MBarMark.ToString() + "." + tbValue[m].SBarMark.ToString() + tbValue[m].CBarMark;
                            else
                                value = tbValue[m].MBarMark.ToString() + "\\P(" + tbValue[m].CBarMark + ")";
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                            tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                            tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                            tb.Cells[m + 2, n].Contents[0].TextStyleId = id;

                            n++;
                            tb.Cells[m + 2, n].TextString = tbValue[m].Diameter.ToString(); //获取i行j列数据
                            tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                            tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                            tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                            tb.Cells[m + 2, n].Contents[0].TextStyleId = id;

                            //Formula
                            n = n + 2;
                            tb.Cells[m + 2, n].TextString = tbValue[m].Formula == null ? "-" : tbValue[m].Formula; //获取i行j列数据
                            tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                            tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                            tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                            tb.Cells[m + 2, n].Contents[0].TextStyleId = id;

                            //R
                            n++;
                            value = "";
                            if (tbValue[m].R != 0)
                                value = tbValue[m].R.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //d
                            n++;
                            value = "";
                            if (tbValue[m].Diameter != 0)
                            {
                                value = System.Text.RegularExpressions.Regex.Replace(tbValue[m].Diameter.ToString(), @"[^0-9]+", "");
                            }
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //r
                            n++;
                            value = "";
                            if (tbValue[m].r != 0)
                                value = tbValue[m].r.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //h
                            n++;
                            value = "";
                            if (tbValue[m].h != 0)
                                value = tbValue[m].h.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //n
                            n++;
                            value = "";
                            if (tbValue[m].n != 0)
                                value = tbValue[m].n.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //Lx
                            n++;
                            value = "";
                            if (tbValue[m].Lx != 0)
                                value = tbValue[m].Lx.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //A
                            n++;
                            value = "";
                            if (tbValue[m].A != 0)
                                value = tbValue[m].A.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //B
                            n++;
                            value = "";
                            if (tbValue[m].B != 0)
                                value = tbValue[m].B.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //C
                            n++;
                            value = "";
                            if (tbValue[m].C != 0)
                                value = tbValue[m].C.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //D
                            n++;
                            value = "";
                            if (tbValue[m].D != 0)
                                value = tbValue[m].D.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }
                            //E
                            n++;
                            value = "";
                            if (tbValue[m].E != 0)
                                value = tbValue[m].E.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }
                            //Quantity
                            n++;
                            value = "";
                            if (tbValue[m].Quantity != 0)
                                value = tbValue[m].Quantity.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //Length
                            n++;
                            value = "";
                            if (tbValue[m].Length != 0)
                                value = tbValue[m].Length.ToString("0.000").Trim();

                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].TextString = value;// string.Format("{0:N3}", double.Parse(value)); //获取i行j列数据
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //TotalLength
                            n++;
                            value = "";
                            if (tbValue[m].TotalLength != 0)
                                value = tbValue[m].TotalLength.ToString("0.000").Trim();

                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].TextString = value;// string.Format("{0:N3}", double.Parse(value));
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //UnitWeight
                            n++;
                            value = "";
                            if (tbValue[m].UnitWeight != 0)
                                value = tbValue[m].UnitWeight.ToString("0.000").Trim();

                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].TextString = value;// string.Format("{0:N3}", double.Parse(value));
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //TotalWeight
                            n++;
                            value = "";
                            if (tbValue[m].TotalWeight != 0)
                                value = tbValue[m].TotalWeight.ToString("0.000").Trim();

                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].TextString = value;// string.Format("{0:N3}", double.Parse(value));
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                                if (m % 4 == 0)
                                    tb.MergeCells(CellRange.Create(tb, m + 2, 2, m + 3, 2));
                            }

                            if (tbValue[m].ShapeConfg.ToString().Contains("MO"))
                                _blcName = "MO";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MUC"))
                                _blcName = "MUC";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MUR"))
                                _blcName = "MUR";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MU"))
                                _blcName = "MU";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MSZR"))
                                _blcName = "MSZR";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MSZ"))
                                _blcName = "MSZ";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MIXCR"))
                                _blcName = "MIXCR0";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MIXC"))
                                _blcName = "MIXC0";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MIXAR"))
                                _blcName = "MIXAR0";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MIXA"))
                                _blcName = "MIXA0";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MA"))
                                _blcName = "MA";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MCT"))
                                _blcName = "MCT";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MCB"))
                                _blcName = "MCB";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MCR"))
                                _blcName = "MCR";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MCL"))
                                _blcName = "MCL";
                            db.CopyBlockFromFile(_dwgPath, _blcName);
                            int co = 0;
                            if (m / 4.0 > (int)m / 4)
                                co = (int)m / 4 + 1;
                            else
                                co = (int)m / 4;
                            if (m % 4 == 0)
                            {
                                if (m == 0)
                                    BlockTool.InsertBlockReference(startPoint.Convert3D(4 * 3 * scale + 5 * 3 * scale + 8 * 3 * scale, -(9 * scale + 16 * scale + 15 * m + 8)), 0.8, _blcName, _dwgPath, 0);
                                else
                                    BlockTool.InsertBlockReference(startPoint.Convert3D(4 * 3 * scale + 5 * 3 * scale + 8 * 3 * scale, -(9 * scale + 16 * scale + 15 * (m - co * 2) + 18 * co + 11)), 0.8, _blcName, _dwgPath, 0);
                            }
                            else if (m % 4 == 2 || m % 4 == 3)
                                BlockTool.InsertBlockReference(startPoint.Convert3D(4 * 3 * scale + 5 * 3 * scale + 8 * 3 * scale, -(9 * scale + 16 * scale + 15 * (m - co * 2) + 18 * co + 8)), 0.8, _blcName, _dwgPath, 0);

                        }
                        catch (Exception ex)
                        { }

                    }
                }

                #endregion

                #region 表格添加数据

                #endregion

                #region 设置列宽
                // 设置列宽
                for (int i = 0; i < colNum; ++i)
                {
                    if (i == 0)
                        tb.Columns[i].Width = 5 * 3 * scale;
                    else if (i == 1)
                        tb.Columns[i].Width = 5 * 3 * scale;
                    else if (i == 2)
                        tb.Columns[i].Width = 16 * 3 * scale;
                    else if (i == 3)
                        tb.Columns[i].Width = 11 * 3 * scale;
                    else if (i > headName.Count - 4)
                        tb.Columns[i].Width = 9 * 3 * scale;
                    else if (i > headName.Count - 6)
                        tb.Columns[i].Width = 8 * 3 * scale;
                    else
                        tb.Columns[i].Width = 4 * 3 * scale;
                }
                #endregion

                //行高
                for (int i = 2; i < rowNum; ++i)
                {
                    if ((i + 2) % 4 == 0 || (i + 2) % 4 == 1)
                        tb.Rows[i].Height = 9 * scale;
                    else
                        tb.Rows[i].Height = 15 * scale;
                }

                #region 列单元格合并



                #endregion

                tb.Layer = "细线";
                tb.LineWeight = LineWeight.LineWeight013;
                tb.ColorIndex = 4;
                modelSpace.AppendEntity(tb);
                tr.AddNewlyCreatedDBObject(tb, true);
                ext = ext.Add(new Extents2d(tb.Bounds.Value.MinPoint.Convert2D(), tb.Bounds.Value.MaxPoint.Convert2D()));

                #region  边框粗线设置
                List<Point2d> pList = new List<Point2d>();
                Point2d pt1 = startPoint.Convert2D();
                pList.Add(pt1);
                Point2d pt2 = pt1.Convert2D(0, -tb.Height);
                pList.Add(pt2);
                Point2d pt3 = pt1.Convert2D(tb.Width, -tb.Height);
                pList.Add(pt3);
                Point2d pt4 = pt1.Convert2D(tb.Width, 0);
                pList.Add(pt4);
                PolylinePloter.AddPolylineByList(db, ref ext, pList, "粗线", 2);
                #endregion

                #endregion

                #region 其他页

                #endregion
                tr.Commit();
                return tb;
            }

        }
        public static Table DrawTwoPdfColumnTableNew_old(Database db, ref Extents2d ext, ref Extents2d ext1, Point3d startPoint,
string txtStyle, double scale, Tuple<string, RebarCollection, double, int> tuple, string title = "MAINLINE")
        {
            int rowNum = 2 + tuple.Item2.Count;

            string pierName = tuple.Item1;
            int bufferCount = (int)tuple.Item4;
            //表格表头
            List<string> headName = new List<string>();
            headName.Add("Bar\\PMark");
            headName.Add("Reinf.\\PType");
            headName.Add("Sharp Configuration");
            headName.Add("Typical\\PFormula");
            headName.Add("R\\P(mm)");
            headName.Add("d\\P(mm)");
            headName.Add("r\\P(mm)");
            headName.Add("h\\P(mm)");
            headName.Add("n\\P(mm)");
            headName.Add("Lx\\P(mm)");
            headName.Add("A\\P(mm)");
            headName.Add("B\\P(mm)");
            headName.Add("C\\P(mm)");
            headName.Add("D\\P(mm)");
            headName.Add("E\\P(mm)");
            headName.Add("Quantity\\P(No./Ea.)");
            headName.Add("Length\\P(m./Ea.)");
            headName.Add("Total Length\\P(m)");
            headName.Add("Unit Weight\\P(kg/m)");
            headName.Add("Total Weight\\P(kg)");
            tbH = 0;


            //int rowNum = tbValue.Count + 2;
            Table tb = new Table();
            // 创建table 
            for (int num = 0; num < 2; num++)
            {
                using (Transaction tr = db.TransactionManager.StartTransaction())
                {
                    BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForWrite) as BlockTable;
                    BlockTableRecord modelSpace = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace],
                        OpenMode.ForWrite) as BlockTableRecord;

                    ObjectId id;
                    TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                    id = st[txtStyle];
                    startPoint = startPoint.Convert3D(420 * num);
                    if (num == 0)
                        rowNum = 2 + 12;
                    else
                        rowNum = 2 + tuple.Item2.Count - 12;
                    tb = new Table();
                    int colNum = headName.Count;
                    tb.SetSize(rowNum, colNum);       // 设置几行几列
                    tb.Position = startPoint;
                    tb.GenerateLayout();
                    #region 第一页
                    #region 第一行 标题


                    tb.Cells[0, 0].TextString = String.Format("TABLE OF REINFORCEMENT BAR LIST OF CONCRETE BUFFER  FOR {0} OF " + title + "({1} CONCRETE BUFFER)",
                           pierName, bufferCount);

                    tb.Cells[0, 0].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[0, 0].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[0, 0].Contents[0].Rotation = 0;
                    //tb.Cells[0, 0].Borders.Horizontal.Margin = 1 * scale;
                    tb.Cells[0, 0].Contents[0].TextStyleId = id;
                    #endregion
                    tb.Rows[0].Height = 9 * scale;

                    #region 第二行 表格标题
                    for (int i = 0; i < colNum; ++i)
                    {
                        tb.Cells[1, i].TextString = headName[i]; //获取i行j列数据
                        tb.Cells[1, i].Contents[0].TextHeight = 2.5 * scale;
                        tb.Cells[1, i].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[1, i].Contents[0].Rotation = 0;
                        tb.Cells[1, i].Borders.Horizontal.Margin = 1 * scale;
                        tb.Cells[1, i].Contents[0].TextStyleId = id;
                    }
                    #endregion

                    tb.Rows[1].Height = 16 * scale;

                    #region 设置表格值
                    RebarCollection tbValue = tuple.Item2;
                    if (tbValue.Count > 0)
                    {
                        int startNo = 0, endNo = 12;
                        if (num == 0)
                        {
                            startNo = 0;
                            endNo = 12;
                        }
                        else
                        {
                            startNo = 12;
                            endNo = tbValue.Count;
                        }
                        for (int m = startNo; m < endNo; m++)
                        {
                            try
                            {
                                //
                                string value = "";
                                int n = 0;
                                value = tbValue[m].MBarMark.ToString();
                                if (tbValue[m].SBarMark != 0)
                                    value = tbValue[m].MBarMark.ToString() + "." + tbValue[m].SBarMark.ToString() + tbValue[m].CBarMark;
                                else
                                    value = tbValue[m].MBarMark.ToString() + "\\P(" + tbValue[m].CBarMark + ")";
                                tb.Cells[m + 2 - startNo, n].TextString = value; //获取i行j列数据
                                tb.Cells[m + 2 - startNo, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2 - startNo, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2 - startNo, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2 - startNo, n].Contents[0].TextStyleId = id;

                                n++;
                                tb.Cells[m + 2 - startNo, n].TextString = tbValue[m].Diameter.ToString(); //获取i行j列数据
                                tb.Cells[m + 2 - startNo, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2 - startNo, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2 - startNo, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2 - startNo, n].Contents[0].TextStyleId = id;

                                //Formula
                                n = n + 2;
                                tb.Cells[m + 2 - startNo, n].TextString = tbValue[m].Formula == null ? "-" : tbValue[m].Formula; //获取i行j列数据
                                tb.Cells[m + 2 - startNo, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2 - startNo, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2 - startNo, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2 - startNo, n].Contents[0].TextStyleId = id;

                                //R
                                n++;
                                value = "";
                                if (tbValue[m].R != 0)
                                    value = tbValue[m].R.ToString();
                                tb.Cells[m + 2 - startNo, n].TextString = value; //获取i行j列数据
                                if (!string.IsNullOrWhiteSpace(value))
                                {
                                    tb.Cells[m + 2 - startNo, n].Contents[0].TextHeight = 2 * scale;
                                    tb.Cells[m + 2 - startNo, n].Alignment = CellAlignment.MiddleCenter;
                                    tb.Cells[m + 2 - startNo, n].Borders.Horizontal.Margin = 1 * scale;
                                    tb.Cells[m + 2 - startNo, n].Contents[0].TextStyleId = id;
                                }

                                //d
                                n++;
                                value = "";
                                if (tbValue[m].Diameter != 0)
                                {
                                    value = System.Text.RegularExpressions.Regex.Replace(tbValue[m].Diameter.ToString(), @"[^0-9]+", "");
                                }
                                tb.Cells[m + 2 - startNo, n].TextString = value; //获取i行j列数据
                                if (!string.IsNullOrWhiteSpace(value))
                                {
                                    tb.Cells[m + 2 - startNo, n].Contents[0].TextHeight = 2 * scale;
                                    tb.Cells[m + 2 - startNo, n].Alignment = CellAlignment.MiddleCenter;
                                    tb.Cells[m + 2 - startNo, n].Borders.Horizontal.Margin = 1 * scale;
                                    tb.Cells[m + 2 - startNo, n].Contents[0].TextStyleId = id;
                                }

                                //r
                                n++;
                                value = "";
                                if (tbValue[m].r != 0)
                                    value = tbValue[m].r.ToString();
                                tb.Cells[m + 2 - startNo, n].TextString = value; //获取i行j列数据
                                if (!string.IsNullOrWhiteSpace(value))
                                {
                                    tb.Cells[m + 2 - startNo, n].Contents[0].TextHeight = 2 * scale;
                                    tb.Cells[m + 2 - startNo, n].Alignment = CellAlignment.MiddleCenter;
                                    tb.Cells[m + 2 - startNo, n].Borders.Horizontal.Margin = 1 * scale;
                                    tb.Cells[m + 2 - startNo, n].Contents[0].TextStyleId = id;
                                }

                                //h
                                n++;
                                value = "";
                                if (tbValue[m].h != 0)
                                    value = tbValue[m].h.ToString();
                                tb.Cells[m + 2 - startNo, n].TextString = value; //获取i行j列数据
                                if (!string.IsNullOrWhiteSpace(value))
                                {
                                    tb.Cells[m + 2 - startNo, n].Contents[0].TextHeight = 2 * scale;
                                    tb.Cells[m + 2 - startNo, n].Alignment = CellAlignment.MiddleCenter;
                                    tb.Cells[m + 2 - startNo, n].Borders.Horizontal.Margin = 1 * scale;
                                    tb.Cells[m + 2 - startNo, n].Contents[0].TextStyleId = id;
                                }

                                //n
                                n++;
                                value = "";
                                if (tbValue[m].n != 0)
                                    value = tbValue[m].n.ToString();
                                tb.Cells[m + 2 - startNo, n].TextString = value; //获取i行j列数据
                                if (!string.IsNullOrWhiteSpace(value))
                                {
                                    tb.Cells[m + 2 - startNo, n].Contents[0].TextHeight = 2 * scale;
                                    tb.Cells[m + 2 - startNo, n].Alignment = CellAlignment.MiddleCenter;
                                    tb.Cells[m + 2 - startNo, n].Borders.Horizontal.Margin = 1 * scale;
                                    tb.Cells[m + 2 - startNo, n].Contents[0].TextStyleId = id;
                                }

                                //Lx
                                n++;
                                value = "";
                                if (tbValue[m].Lx != 0)
                                    value = tbValue[m].Lx.ToString();
                                tb.Cells[m + 2 - startNo, n].TextString = value; //获取i行j列数据
                                if (!string.IsNullOrWhiteSpace(value))
                                {
                                    tb.Cells[m + 2 - startNo, n].Contents[0].TextHeight = 2 * scale;
                                    tb.Cells[m + 2 - startNo, n].Alignment = CellAlignment.MiddleCenter;
                                    tb.Cells[m + 2 - startNo, n].Borders.Horizontal.Margin = 1 * scale;
                                    tb.Cells[m + 2 - startNo, n].Contents[0].TextStyleId = id;
                                }

                                //A
                                n++;
                                value = "";
                                if (tbValue[m].A != 0)
                                    value = tbValue[m].A.ToString();
                                tb.Cells[m + 2 - startNo, n].TextString = value; //获取i行j列数据
                                if (!string.IsNullOrWhiteSpace(value))
                                {
                                    tb.Cells[m + 2 - startNo, n].Contents[0].TextHeight = 2 * scale;
                                    tb.Cells[m + 2 - startNo, n].Alignment = CellAlignment.MiddleCenter;
                                    tb.Cells[m + 2 - startNo, n].Borders.Horizontal.Margin = 1 * scale;
                                    tb.Cells[m + 2 - startNo, n].Contents[0].TextStyleId = id;
                                }

                                //B
                                n++;
                                value = "";
                                if (tbValue[m].B != 0)
                                    value = tbValue[m].B.ToString();
                                tb.Cells[m + 2 - startNo, n].TextString = value; //获取i行j列数据
                                if (!string.IsNullOrWhiteSpace(value))
                                {
                                    tb.Cells[m + 2 - startNo, n].Contents[0].TextHeight = 2 * scale;
                                    tb.Cells[m + 2 - startNo, n].Alignment = CellAlignment.MiddleCenter;
                                    tb.Cells[m + 2 - startNo, n].Borders.Horizontal.Margin = 1 * scale;
                                    tb.Cells[m + 2 - startNo, n].Contents[0].TextStyleId = id;

                                }

                                //C
                                n++;
                                value = "";
                                if (tbValue[m].C != 0)
                                    value = tbValue[m].C.ToString();
                                tb.Cells[m + 2 - startNo, n].TextString = value; //获取i行j列数据
                                if (!string.IsNullOrWhiteSpace(value))
                                {
                                    tb.Cells[m + 2 - startNo, n].Contents[0].TextHeight = 2 * scale;
                                    tb.Cells[m + 2 - startNo, n].Alignment = CellAlignment.MiddleCenter;
                                    tb.Cells[m + 2 - startNo, n].Borders.Horizontal.Margin = 1 * scale;
                                    tb.Cells[m + 2 - startNo, n].Contents[0].TextStyleId = id;
                                }

                                //D
                                n++;
                                value = "";
                                if (tbValue[m].D != 0)
                                    value = tbValue[m].D.ToString();
                                tb.Cells[m + 2 - startNo, n].TextString = value; //获取i行j列数据
                                if (!string.IsNullOrWhiteSpace(value))
                                {
                                    tb.Cells[m + 2 - startNo, n].Contents[0].TextHeight = 2 * scale;
                                    tb.Cells[m + 2 - startNo, n].Alignment = CellAlignment.MiddleCenter;
                                    tb.Cells[m + 2 - startNo, n].Borders.Horizontal.Margin = 1 * scale;
                                    tb.Cells[m + 2 - startNo, n].Contents[0].TextStyleId = id;
                                }
                                //E
                                n++;
                                value = "";
                                if (tbValue[m].E != 0)
                                    value = tbValue[m].E.ToString();
                                tb.Cells[m + 2 - startNo, n].TextString = value; //获取i行j列数据
                                if (!string.IsNullOrWhiteSpace(value))
                                {
                                    tb.Cells[m + 2 - startNo, n].Contents[0].TextHeight = 2 * scale;
                                    tb.Cells[m + 2 - startNo, n].Alignment = CellAlignment.MiddleCenter;
                                    tb.Cells[m + 2 - startNo, n].Borders.Horizontal.Margin = 1 * scale;
                                    tb.Cells[m + 2 - startNo, n].Contents[0].TextStyleId = id;
                                }
                                //Quantity
                                n++;
                                value = "";
                                if (tbValue[m].Quantity != 0)
                                    value = tbValue[m].Quantity.ToString();
                                tb.Cells[m + 2 - startNo, n].TextString = value; //获取i行j列数据
                                if (!string.IsNullOrWhiteSpace(value))
                                {
                                    tb.Cells[m + 2 - startNo, n].Contents[0].TextHeight = 2 * scale;
                                    tb.Cells[m + 2 - startNo, n].Alignment = CellAlignment.MiddleCenter;
                                    tb.Cells[m + 2 - startNo, n].Borders.Horizontal.Margin = 1 * scale;
                                    tb.Cells[m + 2 - startNo, n].Contents[0].TextStyleId = id;
                                }

                                //Length
                                n++;
                                value = "";
                                if (tbValue[m].Length != 0)
                                    value = tbValue[m].Length.ToString("0.000").Trim();

                                if (!string.IsNullOrWhiteSpace(value))
                                {
                                    tb.Cells[m + 2 - startNo, n].TextString = value;// string.Format("{0:N3}", double.Parse(value)); //获取i行j列数据
                                    tb.Cells[m + 2 - startNo, n].Contents[0].TextHeight = 2 * scale;
                                    tb.Cells[m + 2 - startNo, n].Alignment = CellAlignment.MiddleCenter;
                                    tb.Cells[m + 2 - startNo, n].Borders.Horizontal.Margin = 1 * scale;
                                    tb.Cells[m + 2 - startNo, n].Contents[0].TextStyleId = id;
                                }

                                //TotalLength
                                n++;
                                value = "";
                                if (tbValue[m].TotalLength != 0)
                                    value = tbValue[m].TotalLength.ToString("0.000").Trim();

                                if (!string.IsNullOrWhiteSpace(value))
                                {
                                    tb.Cells[m + 2 - startNo, n].TextString = value;// string.Format("{0:N3}", double.Parse(value));
                                    tb.Cells[m + 2 - startNo, n].Contents[0].TextHeight = 2 * scale;
                                    tb.Cells[m + 2 - startNo, n].Alignment = CellAlignment.MiddleCenter;
                                    tb.Cells[m + 2 - startNo, n].Borders.Horizontal.Margin = 1 * scale;
                                    tb.Cells[m + 2 - startNo, n].Contents[0].TextStyleId = id;
                                }

                                //UnitWeight
                                n++;
                                value = "";
                                if (tbValue[m].UnitWeight != 0)
                                    value = tbValue[m].UnitWeight.ToString("0.000").Trim();

                                if (!string.IsNullOrWhiteSpace(value))
                                {
                                    tb.Cells[m + 2 - startNo, n].TextString = value;// string.Format("{0:N3}", double.Parse(value));
                                    tb.Cells[m + 2 - startNo, n].Contents[0].TextHeight = 2 * scale;
                                    tb.Cells[m + 2 - startNo, n].Alignment = CellAlignment.MiddleCenter;
                                    tb.Cells[m + 2 - startNo, n].Borders.Horizontal.Margin = 1 * scale;
                                    tb.Cells[m + 2 - startNo, n].Contents[0].TextStyleId = id;
                                }

                                //TotalWeight
                                n++;
                                value = "";
                                if (tbValue[m].TotalWeight != 0)
                                    value = tbValue[m].TotalWeight.ToString("0.000").Trim();

                                if (!string.IsNullOrWhiteSpace(value))
                                {
                                    tb.Cells[m + 2 - startNo, n].TextString = value;// string.Format("{0:N3}", double.Parse(value));
                                    tb.Cells[m + 2 - startNo, n].Contents[0].TextHeight = 2 * scale;
                                    tb.Cells[m + 2 - startNo, n].Alignment = CellAlignment.MiddleCenter;
                                    tb.Cells[m + 2 - startNo, n].Borders.Horizontal.Margin = 1 * scale;
                                    tb.Cells[m + 2 - startNo, n].Contents[0].TextStyleId = id;
                                    if (m % 4 == 0 && num == 1)
                                        tb.MergeCells(CellRange.Create(tb, m + 2 - startNo, 2, m + 3 - startNo, 2));
                                }

                                if (tbValue[m].ShapeConfg.ToString().Contains("MO"))
                                    _blcName = "MO";
                                else if (tbValue[m].ShapeConfg.ToString().Contains("MUC"))
                                    _blcName = "MUC";
                                else if (tbValue[m].ShapeConfg.ToString().Contains("MUR"))
                                    _blcName = "MUR";
                                else if (tbValue[m].ShapeConfg.ToString().Contains("MU"))
                                    _blcName = "MU";
                                else if (tbValue[m].ShapeConfg.ToString().Contains("MSZR"))
                                    _blcName = "MSZR";
                                else if (tbValue[m].ShapeConfg.ToString().Contains("MSZ"))
                                    _blcName = "MSZ";
                                else if (tbValue[m].ShapeConfg.ToString().Contains("MIXCR"))
                                    _blcName = "MIXCR0";
                                else if (tbValue[m].ShapeConfg.ToString().Contains("MIXC"))
                                    _blcName = "MIXC0";
                                else if (tbValue[m].ShapeConfg.ToString().Contains("MIXAR"))
                                    _blcName = "MIXAR0";
                                else if (tbValue[m].ShapeConfg.ToString().Contains("MIXA"))
                                    _blcName = "MIXA0";
                                else if (tbValue[m].ShapeConfg.ToString().Contains("MA"))
                                    _blcName = "MA";
                                else if (tbValue[m].ShapeConfg.ToString().Contains("MCT"))
                                    _blcName = "MCT";
                                else if (tbValue[m].ShapeConfg.ToString().Contains("MCB"))
                                    _blcName = "MCB";
                                else if (tbValue[m].ShapeConfg.ToString().Contains("MCR"))
                                    _blcName = "MCR";
                                else if (tbValue[m].ShapeConfg.ToString().Contains("MCL"))
                                    _blcName = "MCL";
                                db.CopyBlockFromFile(_dwgPath, _blcName);
                                if (num == 0)
                                    BlockTool.InsertBlockReference(startPoint.Convert3D(4 * 3 * scale + 5 * 3 * scale + 8 * 3 * scale, -(9 * scale + 16 * scale + 16 * (m - startNo) + 8)), 0.8, _blcName, _dwgPath, 0);
                                else
                                {
                                    int co = 0;
                                    if (m / 4.0 > (int)m / 4)
                                        co = (int)(m - startNo) / 4 + 1;
                                    else
                                        co = (int)(m - startNo) / 4;
                                    if (m % 4 == 0)
                                    {
                                        if (m == 0)
                                            BlockTool.InsertBlockReference(startPoint.Convert3D(4 * 3 * scale + 5 * 3 * scale + 8 * 3 * scale, -(9 * scale + 16 * scale + 15 * (m - startNo) + 8)), 0.8, _blcName, _dwgPath, 0);
                                        else
                                            BlockTool.InsertBlockReference(startPoint.Convert3D(4 * 3 * scale + 5 * 3 * scale + 8 * 3 * scale, -(9 * scale + 16 * scale + 15 * (m - startNo - co * 2) + 18 * co + 11)), 0.8, _blcName, _dwgPath, 0);
                                    }
                                    else if (m % 4 == 2 || m % 4 == 3)
                                        BlockTool.InsertBlockReference(startPoint.Convert3D(4 * 3 * scale + 5 * 3 * scale + 8 * 3 * scale, -(9 * scale + 16 * scale + 15 * (m - startNo - co * 2) + 18 * co + 8)), 0.8, _blcName, _dwgPath, 0);
                                }

                            }
                            catch (Exception ex)
                            { }

                        }
                    }

                    #endregion

                    #region 表格添加数据

                    #endregion

                    #region 设置列宽
                    // 设置列宽
                    for (int i = 0; i < colNum; ++i)
                    {
                        if (i == 0)
                            tb.Columns[i].Width = 5 * 3 * scale;
                        else if (i == 1)
                            tb.Columns[i].Width = 5 * 3 * scale;
                        else if (i == 2)
                            tb.Columns[i].Width = 16 * 3 * scale;
                        else if (i == 3)
                            tb.Columns[i].Width = 11 * 3 * scale;
                        else if (i > headName.Count - 4)
                            tb.Columns[i].Width = 9 * 3 * scale;
                        else if (i > headName.Count - 6)
                            tb.Columns[i].Width = 8 * 3 * scale;
                        else
                            tb.Columns[i].Width = 4 * 3 * scale;
                    }
                    #endregion

                    //行高
                    for (int i = 2; i < rowNum; ++i)
                    {
                        if (num == 0)
                            tb.Rows[i].Height = 16 * scale;
                        else
                        {
                            if ((i + 2) % 4 == 0 || (i + 2) % 4 == 1)
                                tb.Rows[i].Height = 9 * scale;
                            else
                                tb.Rows[i].Height = 15 * scale;
                        }
                    }

                    #region 列单元格合并



                    #endregion

                    tb.Layer = "细线";
                    tb.LineWeight = LineWeight.LineWeight013;
                    tb.ColorIndex = 4;
                    modelSpace.AppendEntity(tb);
                    tr.AddNewlyCreatedDBObject(tb, true);
                    if (num == 0)
                        ext = ext.Add(new Extents2d(tb.Bounds.Value.MinPoint.Convert2D(), tb.Bounds.Value.MaxPoint.Convert2D()));
                    else
                        ext1 = ext1.Add(new Extents2d(tb.Bounds.Value.MinPoint.Convert2D(), tb.Bounds.Value.MaxPoint.Convert2D()));

                    #region  边框粗线设置
                    List<Point2d> pList = new List<Point2d>();
                    Point2d pt1 = startPoint.Convert2D();
                    pList.Add(pt1);
                    Point2d pt2 = pt1.Convert2D(0, -tb.Height);
                    pList.Add(pt2);
                    Point2d pt3 = pt1.Convert2D(tb.Width, -tb.Height);
                    pList.Add(pt3);
                    Point2d pt4 = pt1.Convert2D(tb.Width, 0);
                    pList.Add(pt4);
                    if (num == 0)
                        PolylinePloter.AddPolylineByList(db, ref ext, pList, "粗线", 2);
                    else
                        PolylinePloter.AddPolylineByList(db, ref ext1, pList, "粗线", 2);
                    #endregion

                    #endregion

                    #region 其他页

                    #endregion
                    tr.Commit();
                }

            }
            return tb;
        }

    }
}
